Skip to content

Commit

Permalink
Update: Add support for parens on left side for-loops (fixes: #8393)
Browse files Browse the repository at this point in the history
  • Loading branch information
VictorHom committed Jun 3, 2017
1 parent 4731ca7 commit 4e7aa1a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/rules/no-extra-parens.js
Expand Up @@ -265,10 +265,11 @@ module.exports = {
const nextTwoTokens = sourceCode.getTokensAfter(node, { count: 2 });
const rightParenToken = nextTwoTokens[0];
const tokenAfterRightParen = nextTwoTokens[1];
const tokenBeforeRightParen = sourceCode.getLastToken(node);

return rightParenToken && tokenAfterRightParen &&
!sourceCode.isSpaceBetweenTokens(rightParenToken, tokenAfterRightParen) &&
tokenAfterRightParen.type === "Keyword";
!astUtils.canTokensBeAdjacent(tokenBeforeRightParen, tokenAfterRightParen);
}

/**
Expand Down
9 changes: 9 additions & 0 deletions tests/lib/rules/no-extra-parens.js
Expand Up @@ -1009,6 +1009,13 @@ ruleTester.run("no-extra-parens", rule, {
1,
{ parserOptions: { ecmaVersion: 2015 } }
),
invalid(
"for ((foo['bar'])of baz);",
"for (foo['bar']of baz);",
"MemberExpression",
1,
{ parserOptions: { ecmaVersion: 2015 } }
),
invalid(
"() => (({ foo: 1 }).foo)",
"() => ({ foo: 1 }).foo",
Expand All @@ -1018,3 +1025,5 @@ ruleTester.run("no-extra-parens", rule, {
)
]
});


0 comments on commit 4e7aa1a

Please sign in to comment.