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.

no-sequences rule in arrow function body returning object is not aplicable

See original GitHub issue

In short: It is not possible to apply no-sequences rule in return part of arrow function in form <argumentList> => <expression> where <expression> is <objectLiteral> because this object literal must be enclosed in parentheses.

Example: I have this bad piece of code and want no-sequences rule to warn me about:

export default injectIntl(connect(state => ({
  auth: state.auth,
}, { // <-- BAD
  login,
}))(LoginForm));

no-sequences rule is not designed for this situation. Correct code should be:

export default injectIntl(connect(state => ({
  auth: state.auth,
}), {
  login,
})(LoginForm));

Sadly, both samples executes and both without lint warnings. Rule no-sequences is not applied if comma expression is explicitly enclosed in parentheses. But it is also impossible to write arrow function returning object without enclosing it into parenthese so no-sequences rule is not usable in this case.

Proposed Solution

If there is arrow (e.g. (arg) => ({result: arg})), no-sequences rule can be enabled in result expression (this is {result: arg} inside parentheses) So it can report if it spot (arg) => ({result: arg}, {foo: 123})

The rule is not fired because of this on line 95 of the no-sequences rule:

if (isParenthesised(node)) {
    return;
}

Should be changed to something similar to:

if (isParenthesised(node) && !isArrowFunctionReturnExpression(node)) {
    return;
}

Thanks to @pedrottimark and @vitorbal for help on Gitter.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
langpavelcommented, May 4, 2016

You are blazingly fast! Thanks!

1reaction
mysticateacommented, May 4, 2016

Thank you for this issue.

I confirmed it on the online demo. image

I’ll fix it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Arrow function expressions - JavaScript - MDN Web Docs
Returning object literals using the concise body syntax (params) => { object: literal } does not work as expected.
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 >
Understanding Arrow Functions in JavaScript
Arrow functions are a new way to write anonymous function expressions in JavaScript, and are similar to lambda functions in some other ...
Read more >
Arrow Functions · Styleguide JavaScript
If the function body consists of a single statement returning an expression without side effects, omit the braces and use the implicit return....
Read more >
Introducing Arrow Functions | Advanced JavaScript
Arrow functions are not named and not bound to an identifier. This means that an arrow function is created dynamically and is not...
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