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: fix no-extra-parens ignores some nodes #11909

Merged
merged 4 commits into from Aug 18, 2019
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
16 changes: 15 additions & 1 deletion lib/rules/no-extra-parens.js
Expand Up @@ -973,7 +973,21 @@ module.exports = {

SpreadElement: checkSpreadOperator,
SpreadProperty: checkSpreadOperator,
ExperimentalSpreadProperty: checkSpreadOperator
ExperimentalSpreadProperty: checkSpreadOperator,

TemplateLiteral(node) {
node.expressions
.filter(e => e && hasExcessParens(e))
.forEach(report);
},

AssignmentPattern(node) {
const { right } = node;

if (right && hasExcessParens(right) && precedence(right) >= PRECEDENCE_OF_ASSIGNMENT_EXPR) {
report(right);
}
}
};

}
Expand Down
6 changes: 6 additions & 0 deletions tests/lib/rules/no-extra-parens.js
Expand Up @@ -1174,6 +1174,12 @@ ruleTester.run("no-extra-parens", rule, {
"Identifier",
1
),
invalid("let s = `${(v)}`", "let s = `${v}`", "Identifier"),
invalid("let s = `${(a, b)}`", "let s = `${a, b}`", "SequenceExpression"),
invalid("function foo(a = (b)) {}", "function foo(a = b) {}", "Identifier"),
invalid("const bar = (a = (b)) => a", "const bar = (a = b) => a", "Identifier"),
invalid("const [a = (b)] = []", "const [a = b] = []", "Identifier"),
invalid("const {a = (b)} = {}", "const {a = b} = {}", "Identifier"),

// https://github.com/eslint/eslint/issues/11706 (also in valid[])
{
Expand Down