Create `except-object` exception to `arrow-body-style` rule, enforcing explicit return of object literals from arrow functions.
See original GitHub issueThe arrow-body-style
rule enforces braceless function bodies when the function consists of a single return statement.
When constructing arrow functions which return object literals, the return value must be wrapped in parentheses to force its evaluation as an expression.
The proposed new option enforces a block body with an explicit return value for object literals returned from arrow functions.
Valid
var foo = () => { return; { bar: 0 }; };
var foo = () => 0;
Invalid
var foo = () => ({ bar: 0 });
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:37 (37 by maintainers)
Top Results From Across the Web
arrow-body-style - ESLint - Pluggable JavaScript Linter
This rule can enforce or disallow the use of braces around arrow function body. ... it requires braces and an explicit return for...
Read more >Returning Object Literals from Arrow Functions in JavaScript
Here's how to return an object literal from an expression-bodied arrow function as introduced by ECMAScript 2015.
Read more >ECMAScript 6 arrow function that returns an object
Arrow functions implicitly return the expression on the right side of the arrow. eg p => p * 2 will return the result...
Read more >getify/eslint-plugin-proper-arrows
The proper-arrows ESLint plugin provides rules that control the definitions of => arrow functions, restricting them to a narrower and more ...
Read more >ES2015 Arrow Functions
For example, how would we return an object literal using an arrow function? We might naively assume we could do this:
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
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 think we should favor new contributions here.
I’m +1 to
allowObjectLiteralBody: true
suggestion for now. If we get 2 more 👍s I’d say we go with that.