`object-shorthand`: add option to warn on explicit return arrows
See original GitHub issueI think I clicked on the right issue template:
Tell us about your environment
- ESLint Version: 3.9.1
- Node Version: 7
- npm Version: stock 3.x
What parser (default, Babel-ESLint, etc.) are you using? default
Please show your full configuration:
"object-shorthand": "error"
What did you do? Please include the actual source code causing the issue.
const obj = {
foo: () => {},
bar: (x, y) => { const something = foo(); return something(bar); },
};
What did you expect to happen? The rule to prefer:
const obj = {
foo() {},
bar(x, y) { const something = foo(); return something(bar); },
};
What actually happened? Please include the actual, raw output from ESLint. No warning.
Basically, I’d like to add an option to object-shorthand
that prefers concise (named) methods over explicit-return arrow functions.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:3
- Comments:19 (19 by maintainers)
Top Results From Across the Web
object-shorthand - ESLint - Pluggable JavaScript Linter
"avoidExplicitReturnArrows": true indicates that methods are preferred over explicit-return arrow functions for function properties. (By default, the rule ...
Read more >JavaScript Best Practices — Object Shorthand and Arrow ...
In this article, we'll look at using the object literal shorthand syntax, arrow functions for callbacks, and using const most of the time...
Read more >eslint object-shorthand error with variable passed in
An excerpt from eslint regarding the issue: Require Object Literal Shorthand Syntax (object-shorthand) - Rule Details.
Read more >Method definitions - JavaScript - MDN Web Docs
Method definition is a shorter syntax for defining a function property in an object initializer. It can also be used in classes.
Read more >eslint-plugin v6.0.0 - hapi.dev
Functions can still be returned by arrow functions whose bodies use curly braces and an explicit return. This rule does not accept any...
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
Just added the third 👍, marking as accepted!
Just to make sure we’re on the same page, the rule isn’t checking for the presence of
return
, it’s checking for aBlockStatement
as the arrow function body.So this would also get reported:
But this would not get reported: