Skip to content
Permalink
Browse files

Fix: fix no-extra-parens ignores some nodes (#11909)

* 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 4cb78774f6cc687a3c8701462f8c7f7b587ecaf0
Showing with 21 additions and 1 deletion.
  1. +15 −1 lib/rules/no-extra-parens.js
  2. +6 −0 tests/lib/rules/no-extra-parens.js
@@ -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);
}
}
};

}
@@ -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[])
{

0 comments on commit 4cb7877

Please sign in to comment.
You can’t perform that action at this time.