-
Notifications
You must be signed in to change notification settings - Fork 26
Style rule: Arrow function with concise body #72
Comments
Actually, I revise my position. I'm ambivalent towards this. |
@skeggse I was talking not of any personal dislike but of a feature introduced in ES6 to promote brevity and better FP-style code in JS. The "mandatory curly braces in arrow function body" rule is a judgment that that feature shouldn't have been allowed. |
That's what I was responding to, yes. |
first rule doesn't really matter writing |
That said, the current style also avoided the pitfall of returning var func = () => { foo: 1 }; // func() returns `undefined`
var func = () => ({ foo: 1 }); // func() returns `{ foo: 1 }` |
That is probably one of the reasons for it, there was an issue relating the es6 styleguide discussion, let me see if I can find it |
found it #58 |
@leesei I would argue that's the programmer's burden to ensure. @AdriVanHoudt Thanks for the issue link. It doesn't seem to make it very clear if there was a real consensus on this rule. I would love to have a renewed discussion around it. |
@prashaantt we are having it right now :P the other issue was to provide context on what was already being said about the topic |
The conclusion I see in #58 seems to allow for one-liners with implicit returns: #58 (comment) |
@AdriVanHoudt Well then, what @devinivy said :) I'll just repeat myself that disallowing single line implicit returns for violation of an arbitrary style rule diminishes the language. We should revoke that rule. |
This is the revised guide for arrow function reflecting #58 (comment) #### Function declaration
- Declare functions via assignment
- Arrow function arguments must be enclosed in parentheses
- Arrow function bodies must be enclosed in curly braces (except for single line [concise body](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Functions/Arrow_functions#Function_body))
- No function creation in concise body
- Object returned in concise body must be enclosed in parentheses "Object returned in concise body must be enclosed in parentheses" is a syntax requirement. I'm not sure if it should be included in style guide. #71 is updated accordingly. |
In #58 (comment), "parentheses around object creation allowed Any comment on "single-line-ness"? |
Arrow function will return concise body (single expression without block) by default.
This feature makes inline mapper function really elegant.
https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Functions/Arrow_functions#Function_body
However these two rule forbids usage of concise body:
EDIT: use term 'concise body', revised Right code
The text was updated successfully, but these errors were encountered: