millermedeiros / esformatter

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

Removing spaces in empty arrow function paren setting? #400

Closed JonathanWolfe closed 8 years ago

JonathanWolfe commented 8 years ago

Maybe I'm just missing it, but I can't figure out a setting to remove spaces from inside arrow function that don't have any parameters.

Current output (using default settings):

( ) => process.exit( 0 );
( example ) => process.exit( 0 );
function example() {
    return process.exit( 0 );
}

Desired output:

() => process.exit( 0 );
( example ) => process.exit( 0 );
function example() {
    return process.exit( 0 );
}
millermedeiros commented 8 years ago

we don't have this setting yet! logic is handled by https://github.com/millermedeiros/esformatter/blob/master/lib/hooks/ArrowFunctionExpression.js

I also considered adding a new setting to handle empty blocks/arrays/objects (see #220)

PS: I would accept a pull request that basically just checks if node.startToken is ( and next non-empty token is ); and calls limit.after(node.startToken, 0).. - but having a new option would be awesome.

JonathanWolfe commented 8 years ago

I've tried this a couple different ways since you responded and I can't get it to work.

Crazy Pills

I'm hoping it has something to do with me testing using atom-esformatter and I haven't actually gone crazy.

millermedeiros commented 8 years ago

this was indeed pretty hard to solve. I only figured it after running:

GREP=custom/arrow DEBUG=rocambole:ws:* npm test

and realizing that the ExpressionOpeningParentheses and ExpressionClosingParentheses whitespace was overriding the ParameterList mutations... (took me almost 1h to figure it out)

thanks a lot for the bug report! I would probably not find this edge-case anytime soon.