Uh oh!
There was an error while loading. Please reload this page.
tools: enforce arrow function brace usage linting - #6455
Conversation
If braces are not required for an arrow function body, omit them. Refs: nodejs#6390 (diff)
jasnell
commented
Apr 29, 2016
Not sure about this one. I don't mind omitting the braces for simple, short expressions (I do so myself all the time) but they are quite helpful for readability if the expression is fairly complex. |
@jasnell wrote:
True, although you can add outer parentheses in those cases and it probably is more readable than adding braces: vs. |
jasnell
commented
Apr 29, 2016
Heh, I don't find the outer parens easier to read at all ;) |
Trott
commented
Apr 29, 2016
Fair enough. The other approach, which you may find equally unconvincing, is that if you have a single expression that is so complicated that it needs to be put into a block explicitly for it to be readable, maybe it really shouldn't be a single expression. So: vs. Obviously, some of this is aesthetics and reasonable people will have different opinions on what makes sense. If we can reach consensus here on a single consistent style/rule for arrow functions, then great. If we can't, oh well. ¯_(ツ)_/¯ |
jasnell
commented
Apr 29, 2016
hmmm.. ;-) yeah, I'd rather not have to do that either. I'll stew on it to see if I can come up with some metric around what makes sense here. |
Trott
commented
Apr 29, 2016
@jasnell is the only person to offer an opinion on this so far and he doesn't support it. I'd like to leave this open for another 24-48 hours to give others a chance to offer other opinions. Will close for sure if there is no one who wants to endorse it after that. As the risk of inviting everyone to an Ultimate Bikeshedding Party: /cc @nodejs/collaborators |
addaleax
commented
Apr 30, 2016
Nah, I’d be -1 on this too. Either style can be appropriate, depending on the situation, and sometimes it’s better left to humans to decide what’s more readable for other humans. |
mscdex
commented
Apr 30, 2016
In general I prefer the non-ES6 function syntax, so I would prefer to see braces (not parens) enforced as it is closer to non-ES6 function syntax. |
cjihrig
commented
Apr 30, 2016
I'm a fan of braces always. |
benjamingr
commented
Apr 30, 2016
-1, compare: arr.filter(function(x){returnx>2;}).map(function(x){returnx*3;}).reduce(function(x,y){returnx+y;});With arr.filter(x=>x>2).map(x=>x*3).reduce((x,y)=>x+y)I find the latter a lot more readable and it's gaining a lot of momentum anyway. |
evanlucas
commented
Apr 30, 2016
I find the first a lot more readable. I'm +1 for always requiring parens and curly braces |
@benjamingr The code you describe as more readable would pass this lint rule. EDIT: Oh, I see, your |
Trott
commented
Apr 30, 2016
Unfortunately, always requiring braces would flag 160 problems in over 50 files in the current code base. The proposed rule here, in contrast, flags just 5 files. |
Trott
commented
Apr 30, 2016
As likely everyone suspected, there's a diversity of opinions and reaching consensus isn't going to happen anytime soon. That's about what I expected, but didn't want to assume. I'm going to go ahead and close this. By all means, re-open if you want to champion this or if you think my assessment of the situation is wrong. |
Checklist
Affected core subsystem(s)
tools test lib
Description of change
Enable linting such that if braces are not required for an arrow function body, omit them.
Refs: #6390 (diff) (where there was a nit about this and I'd rather tools tell me code style nits rather than people...)
/cc @bnoordhuis