no-sequences rule in arrow function body returning object is not aplicable
See original GitHub issueIn 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:
- Created 7 years ago
- Comments:10 (6 by maintainers)
Top GitHub Comments
You are blazingly fast! Thanks!
Thank you for this issue.
I confirmed it on the online demo.
I’ll fix it.