arrow-body-style: [2, "as-needed"] should ignore function bodies that return another block/function
See original GitHub issueGranted the below example could be achieved a number of different ways to produce the same results, it’s a use case that I think others might find useful if handled in the way I’m expecting.
The following code will fail ESLint v1.9.0 with arrow-body-style: [2, "as-needed"]
:
function foo() {
return (bar, baz) => { // Unexpected block statement surrounding arrow body. (arrow-body-style)
return qux => {
console.log(bar);
console.log(baz);
console.log(qux);
};
};
}
foo()("bar", "baz")("qux");
I expect the above (contrived currying example) to pass since, as far as I know, a block is required here.
Issue Analytics
- State:
- Created 8 years ago
- Comments:11 (5 by maintainers)
Top Results From Across the Web
arrow-body-style: [2, "as-needed"] should ignore function ...
arrow-body-style : [2, "as-needed"] should ignore function bodies that return another block/function.
Read more >arrow-body-style - ESLint - Pluggable JavaScript Linter
The rule takes one or two options. The first is a string, which can be: "always" enforces braces around the function body; "as-needed"...
Read more >Unexpected block statement surrounding arrow body
This said, if arrow-body-style option is set to true, OP is correct. An other example would be something like this : return this.state.greetings.map((name) ......
Read more >@getify/eslint-plugin-proper-arrows - npm
"object-return" : forbids => arrow functions from returning objects in the concise-expression-body form, such as x => ({ x }) .
Read more >arrow-body-style - ESLint Config
This rule can enforce or disallow the use of braces around arrow function body. What ESLint should do when it catches the rule...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ll second @mattkrick on that, and provide practical example in form of Login.js component:
There is definitely need for such pattern and that need will only increase as we further push the envelope of possibilities that react&redux for example allow.
Please reconsider you position on this.
@elgubenis It’s arrow-body-style’s warning. The arrow functions of your code have only a
return
statement in the body, so you can rewrite them with() => foo
style.