question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`object-shorthand`: add option to warn on explicit return arrows

See original GitHub issue

I 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:closed
  • Created 7 years ago
  • Reactions:3
  • Comments:19 (19 by maintainers)

github_iconTop GitHub Comments

3reactions
btmillscommented, Dec 11, 2016

Just added the third 👍, marking as accepted!

1reaction
not-an-aardvarkcommented, Dec 28, 2016

Just to make sure we’re on the same page, the rule isn’t checking for the presence of return, it’s checking for a BlockStatement as the arrow function body.

So this would also get reported:

var x = {
  foo: () => {
    bar();
    // no return statement
  }
};

But this would not get reported:

var x = {
  foo: () => bar() // body is a CallExpression instead of a BlockStatement
};
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found