millermedeiros / esformatter

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

Allow ">=X" style values for whitespace #437

Open abelnation opened 8 years ago

abelnation commented 8 years ago

The ability to use <>= symbols to configure newlines is extremely useful. It would be awesome to be able to do the same for whitespace and indentations.

millermedeiros commented 8 years ago

You should be able to set indent.value, lineBreak.value and whiteSpace.value.

Feel free to reopen if it doesn't solve your problem.

abelnation commented 8 years ago

Setting the value is very different from specifying the specific number of newlines for a certain token type. I'm not sure how you intended your answer to be a solution.

Look at arrays, for example:

var x = [ 111, 222, 333 ];
var x = [   1,   2,   3 ];
var x = [ 1,   2,   3   ];

By specifying whitespace: ">=1" for inside the array brackets, I can make all 3 of these examples valid.

millermedeiros commented 8 years ago

Ahhhh, now I understood what you meant. Indent is tricky since current logic strips original indentation (hard to handle edge cases and mixed indentation). For white space it shouldn't be too hard.

Thanks for the feature request!

abelnation commented 8 years ago

To add to my example above, would be nice to be able to support the following formatting as well. In otherwords, sometimes leading spaces are used to enforce alignment, and it would be nice if indentation did not interfere with extra spaces added. This one may be harder to support.

// '>' used to represent a tab char shown as 4 spaces
// '⎵' used to represent a space character
var x = [ 
>   -1.0,⎵⎵1.0,⎵⎵1.0,
>   ⎵1.0,⎵-1.0,⎵⎵1.0,
>   ⎵1.0,⎵⎵1.0,⎵-1.0
];
millermedeiros commented 8 years ago

I created a feature request on rocambole-whitespace to support the ">=X", will be good to keep it consistent with rocambole-linebreak, even tho it will increase complexity a little bit. - Pull requests are highly appreciated!


the feature about the extra spaces after the indent is tricky, will need to be implemented as a plugin since that would be considered a "mixed indentation" and our whole indent/whiteSpace logic avoids mixed tokens at the start of the line - we also call indent.sanitize() after the indent step which would remove the white spaces...