millermedeiros / esformatter

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

Multiline Assignment #416

Closed uloco closed 8 years ago

uloco commented 8 years ago

If my line is longer than 100 chars, I wrap the code manually like this:

var foo = "This contains a very long string" + 
  "which should be indented 2 spaces on this line";

This should stay as it is, but esformatter strips the indent like the following:

var foo = "This contains a very long string" + 
"which should be indented 2 spaces on this line";

Even when I place the plus sign on the second line, it won't be indented.

My .esformatter file:

{
  "preset": "default"
}
uloco commented 8 years ago

I set the property SingleVariableDeclaration to 1 and now it works for me. Is this intended behaviour? What is the purpose of this property?

Another problem with this option, now other assignments like this one fail:

Input (and expected behaviour would be not touching this one)

var foo = {
  a: 'a',
  b: 'b'
}

Output

var foo = {
    a: 'a',
    b: 'b'
}
millermedeiros commented 8 years ago

this is supposed to work fine with the default settings, see #212 and also https://github.com/millermedeiros/esformatter/blob/master/test/compare/default/binary_expression-out.js - maybe something else around it (before or after) is removing the indent.

uloco commented 8 years ago

Try it here: http://lloiser.github.io/esformatter-visualize/ It does strip the indent away, when preset is set to default. There is nothing left I can try...

millermedeiros commented 8 years ago

esformatter-visualize is using a really old version of esformatter (0.4.3) - this should definitely work in the latest version (0.9.2).

I never really got the time to create a proper example page (like esformatter-visualize) and keep it in sync with latest esformatter version..

uloco commented 8 years ago

I tried it again and you are right, multiline String assignments work fine. The problem occurs with multiline variable declarations, starting on the new line with a variable, like so:

Input

var foo = bar + baz +
  barbaz;

Output

var foo = bar + baz +
barbaz;