Skip to content

Commit

Permalink
Fix: fix no-extra-parens ignores some nodes (#11909)
Browse files Browse the repository at this point in the history
* Fix: fix on TemplateLiteral

* Fix: fix on AssignmentPattern

* Fix: fix SequenceExpression at TemplateLiteral
  • Loading branch information
g-plane authored and platinumazure committed Aug 18, 2019
1 parent 2dc23b8 commit 4cb7877
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
16 changes: 15 additions & 1 deletion lib/rules/no-extra-parens.js
Expand Up @@ -980,7 +980,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 @@ -1197,6 +1197,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

0 comments on commit 4cb7877

Please sign in to comment.