millermedeiros / esformatter

ECMAScript code beautifier/formatter
MIT License
970 stars 91 forks source link

--diff should show the corresponding applied rules #331

Open vvo opened 9 years ago

vvo commented 9 years ago

What I find hard to do is tuning esformatter for some rules. Because when doing esformatter --diff, we do not know what would be the the applied rules for each modification.

Do you think that's feasible?

millermedeiros commented 9 years ago

it wasn't really clear to me how that feature would work, can you provide the expected output? (even if it's just a rough idea, just so we can get the conversation going)

vvo commented 9 years ago

Given this error:

2015-07-08-154844_1052x119_scrot

We could have:

77 | <LF>
-- | rule: `lineBreak.after.expre..: >= 1` =>
78 | zuulConfig.browsers =<LF>
79 |   process.env.TRAVIS_PULL_REQUEST && process.env.TRAVIS_PULL_REQUEST !== 'false' ?<LF>
80 |     browsers.pullRequest :<LF>
81 |     browsers.all;<LF>

?

millermedeiros commented 9 years ago

that is tricky to implement.. right now we just compare the input with the output and do a basic string diff.

to know which parts of the code are not obeying the rules we would need to store the differences on all the line break and white space limit calls (eg. expected 2 line breaks, found 1) and after the whole transformation it would need to map the diffs with the line number (code formatting starts from the "leaf" nodes, so line numbers change a lot during the transformation).

indentation is a totally different process and we don't really know how many indents the original program had.. (and there is no precise way to do it because of mixed indentation and odd numbers..)

but I agree that it would be easier to configure esformatter with some sort of help, maybe we could do it through an UI that allow user to hover the code fragments and display the token/node type and which settings are applied to that part of the code..

vvo commented 9 years ago

Yep esformatter is great but was hard to configure, once set it's good. Good luck, I was only raising the issue, I really can't help more :)

millermedeiros commented 9 years ago

@vvo keep the bug reports and suggestions coming. it's good to have feedback.

hadri3n commented 8 years ago

+1