Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix: no-extra-parens export default sequence expression false positive (
  • Loading branch information
mdjermanovic committed Apr 6, 2020
1 parent af4472f commit 301b450
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 3 deletions.
6 changes: 5 additions & 1 deletion lib/rules/no-extra-parens.js
Expand Up @@ -560,7 +560,11 @@ module.exports = {
tokensToIgnore.add(secondToken);
}

if (hasExcessParens(node)) {
const hasExtraParens = node.parent.type === "ExportDefaultDeclaration"
? hasExcessParensWithPrecedence(node, PRECEDENCE_OF_ASSIGNMENT_EXPR)
: hasExcessParens(node);

if (hasExtraParens) {
report(node);
}
}
Expand Down
57 changes: 55 additions & 2 deletions tests/lib/rules/no-extra-parens.js
Expand Up @@ -530,13 +530,17 @@ ruleTester.run("no-extra-parens", rule, {
"() => ({ foo: 1 }).foo",
"() => ({ foo: 1 }.foo().bar).baz.qux()",
"() => ({ foo: 1 }.foo().bar + baz)",
{
code: "export default (a, b)",
parserOptions: { sourceType: "module" }
},
{
code: "export default (function(){}).foo",
parserOptions: { ecmaVersion: 6, sourceType: "module" }
parserOptions: { sourceType: "module" }
},
{
code: "export default (class{}).foo",
parserOptions: { ecmaVersion: 6, sourceType: "module" }
parserOptions: { sourceType: "module" }
},
"({}).hasOwnProperty.call(foo, bar)",
"({}) ? foo() : bar()",
Expand Down Expand Up @@ -1358,6 +1362,55 @@ ruleTester.run("no-extra-parens", rule, {
"UpdateExpression",
1
),
invalid(
"export default ((a, b))",
"export default (a, b)",
"SequenceExpression",
1,
{ parserOptions: { sourceType: "module" } }
),
invalid(
"export default (() => {})",
"export default () => {}",
"ArrowFunctionExpression",
1,
{ parserOptions: { sourceType: "module" } }
),
invalid(
"export default ((a, b) => a + b)",
"export default (a, b) => a + b",
"ArrowFunctionExpression",
1,
{ parserOptions: { sourceType: "module" } }
),
invalid(
"export default (a => a)",
"export default a => a",
"ArrowFunctionExpression",
1,
{ parserOptions: { sourceType: "module" } }
),
invalid(
"export default (a = b)",
"export default a = b",
"AssignmentExpression",
1,
{ parserOptions: { sourceType: "module" } }
),
invalid(
"export default (a ? b : c)",
"export default a ? b : c",
"ConditionalExpression",
1,
{ parserOptions: { sourceType: "module" } }
),
invalid(
"export default (a)",
"export default a",
"Identifier",
1,
{ parserOptions: { sourceType: "module" } }
),
invalid(
"for (foo of(bar));",
"for (foo of bar);",
Expand Down

0 comments on commit 301b450

Please sign in to comment.