Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: no-extra-parens invalid autofix in for-of statements #8337

Merged
merged 1 commit into from Mar 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/rules/no-extra-parens.js
Expand Up @@ -318,7 +318,7 @@ module.exports = {
}

// If the parens are preceded by a keyword (e.g. `typeof(0)`), a space should be inserted (`typeof 0`)
const precededByKeyword = tokenBeforeLeftParen.type === "Keyword";
const precededByIdentiferPart = esUtils.code.isIdentifierPartES6(tokenBeforeLeftParen.value.slice(-1).charCodeAt(0));

// However, a space should not be inserted unless the first character of the token is an identifier part
// e.g. `typeof([])` should be fixed to `typeof[]`
Expand All @@ -331,7 +331,7 @@ module.exports = {
const startsWithUnaryPlus = firstToken.type === "Punctuator" && firstToken.value === "+";
const startsWithUnaryMinus = firstToken.type === "Punctuator" && firstToken.value === "-";

return (precededByKeyword && startsWithIdentifierPart) ||
return (precededByIdentiferPart && startsWithIdentifierPart) ||
(precededByUnaryPlus && startsWithUnaryPlus) ||
(precededByUnaryMinus && startsWithUnaryMinus);
}
Expand Down
7 changes: 7 additions & 0 deletions tests/lib/rules/no-extra-parens.js
Expand Up @@ -952,6 +952,13 @@ ruleTester.run("no-extra-parens", rule, {
"AssignmentExpression",
1,
{ parserOptions: { ecmaVersion: 2015 } }
),
invalid(
"for (foo of(bar));",
"for (foo of bar);",
"Identifier",
1,
{ parserOptions: { ecmaVersion: 2015 } }
)
]
});