Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Formatting rule & plugin order #415

Closed
jmullo opened this issue Mar 2, 2016 · 3 comments
Closed

Formatting rule & plugin order #415

jmullo opened this issue Mar 2, 2016 · 3 comments

Comments

@jmullo
Copy link

jmullo commented Mar 2, 2016

It should be possible to configure the order in which plugins are executed.
It should also be possible to configure whether plugins are executed before or after default rules.

Currently if I have "esformatter-use-strict" plugin and "esformatter-quotes" plugin configured to use double quotes, I end up with "use strict" having single quotes in the resulting formatted code.

@millermedeiros
Copy link
Owner

the order that plugins are listed in the array should affect the order they are executed, but some plugins use stringBefore, while others work with tokenBefore or nodeAfter.. and that changes the order that they end up being executed:

The plugin methods are executed in the following order: setOptions > stringBefore > transformBefore > tokenBefore > nodeBefore > nodeAfter > tokenAfter > transformAfter > stringAfter. plugins.md

maybe I should update esformatter-quotes to use tokenAfter instead..

everything is applied in a single pass/loop to improve performance, otherwise every single plugin would require a full loop and there would be no way for us to add something like nodeBefore and nodeAfter...

@twolfson
Copy link

It seems reasonable but a bit of a hack. Maybe we should shift the responsibility of deciding what gets grouped into a single pass to the user?

For example:

plugins: [
  // Group these 2 into single pass
  ['esformatter-quotes', 'esformatter-var-each'],
  // Run as its own pass after the others
  'esformatter-use-strict'
  // Alternative synax: `['esformatter-use-strict']`
],
// Flag to enable new behavior so we can preserve backwards compatibility
//   and performance for default behavior
multiplePasses: true

@millermedeiros
Copy link
Owner

millermedeiros commented Jul 15, 2016

I was planning to implement something similar to what @twolfson suggested but I'm thinking that we should keep the current behavior for now. There are plugins like esformatter-jsx that removes some nodes during stringBefore and restore them during stringAfter... If we allow multiple passes, they would never be able to implement the formatJSXExpressions: false feature.

The esformatter-use-strict plugin should be using stringBefore instead of stringAfter, that way the quotes would be formatted properly. (Or it should be changed to accept the same config as esformatter-quotes)

Sorry, but I'm going to close it as wontfix for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants