Skip to content

Commit

Permalink
Update: fix no-extra-parens CallExpression#callee false negatives (es…
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjermanovic authored and kaicataldo committed Jan 9, 2020
1 parent 14b42c3 commit b2c6209
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
9 changes: 4 additions & 5 deletions lib/rules/no-extra-parens.js
Original file line number Diff line number Diff line change
Expand Up @@ -418,11 +418,10 @@ module.exports = {
hasDoubleExcessParens(callee) ||
!isIIFE(node) && !hasNewParensException && !(

/*
* Allow extra parens around a new expression if
* there are intervening parentheses.
*/
(callee.type === "MemberExpression" && doesMemberExpressionContainCallExpression(callee))
// Allow extra parens around a new expression if they are intervening parentheses.
node.type === "NewExpression" &&
callee.type === "MemberExpression" &&
doesMemberExpressionContainCallExpression(callee)
)
) {
report(node.callee);
Expand Down
6 changes: 6 additions & 0 deletions tests/lib/rules/no-extra-parens.js
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,12 @@ ruleTester.run("no-extra-parens", rule, {
invalid("(new foo.bar()).baz", "new foo.bar().baz", "NewExpression"),
invalid("(new foo.bar()).baz()", "new foo.bar().baz()", "NewExpression"),

invalid("(a)()", "a()", "Identifier"),
invalid("(a.b)()", "a.b()", "MemberExpression"),
invalid("(a())()", "a()()", "CallExpression"),
invalid("(a.b())()", "a.b()()", "CallExpression"),
invalid("(a().b)()", "a().b()", "MemberExpression"),
invalid("(a().b.c)()", "a().b.c()", "MemberExpression"),
invalid("new (A)", "new A", "Identifier"),
invalid("(new A())()", "new A()()", "NewExpression"),
invalid("(new A(1))()", "new A(1)()", "NewExpression"),
Expand Down

0 comments on commit b2c6209

Please sign in to comment.