Skip to content
Permalink
Browse files

Breaking: tweak space-before-function-paren default option (fixes #8267

…) (#8285)

This updates the `asyncArrow` option for space-before-function-paren to be consistent with the other options in the rule. Previously, the user had to explicitly opt-in to async arrow function checking, for backwards compatibility.
  • Loading branch information...
not-an-aardvark authored and ilyavolodin committed Apr 3, 2017
1 parent 0e0dd27 commit 7dd890db194faec55cfd0485118c1a8fdf0b076d
Showing with 21 additions and 8 deletions.
  1. +1 −3 lib/rules/space-before-function-paren.js
  2. +20 −5 tests/lib/rules/space-before-function-paren.js
@@ -87,9 +87,7 @@ module.exports = {

// Always ignore non-async functions and arrow functions without parens, e.g. async foo => bar
if (node.async && astUtils.isOpeningParenToken(sourceCode.getFirstToken(node, { skip: 1 }))) {

// For backwards compatibility, the base config does not apply to async arrow functions.
return overrideConfig.asyncArrow || "ignore";
return overrideConfig.asyncArrow || baseConfig;
}
} else if (isNamedFunction(node)) {
return overrideConfig.named || baseConfig;
@@ -110,13 +110,8 @@ ruleTester.run("space-before-function-paren", rule, {
{ code: "async() => 1", options: [{ asyncArrow: "never" }], parserOptions: { ecmaVersion: 8 } },
{ code: "async () => 1", options: [{ asyncArrow: "ignore" }], parserOptions: { ecmaVersion: 8 } },
{ code: "async() => 1", options: [{ asyncArrow: "ignore" }], parserOptions: { ecmaVersion: 8 } },

// ignore by default for now.
{ code: "async () => 1", parserOptions: { ecmaVersion: 8 } },
{ code: "async() => 1", parserOptions: { ecmaVersion: 8 } },
{ code: "async () => 1", options: ["always"], parserOptions: { ecmaVersion: 8 } },
{ code: "async() => 1", options: ["always"], parserOptions: { ecmaVersion: 8 } },
{ code: "async () => 1", options: ["never"], parserOptions: { ecmaVersion: 8 } },
{ code: "async() => 1", options: ["never"], parserOptions: { ecmaVersion: 8 } }
],

@@ -494,6 +489,26 @@ ruleTester.run("space-before-function-paren", rule, {
options: [{ asyncArrow: "never" }],
parserOptions: { ecmaVersion: 8 },
errors: ["Unexpected space before function parentheses."]
},
{
code: "async() => 1",
output: "async () => 1",
parserOptions: { ecmaVersion: 8 },
errors: [{ message: "Missing space before function parentheses.", type: "ArrowFunctionExpression" }]
},
{
code: "async() => 1",
output: "async () => 1",
options: ["always"],
parserOptions: { ecmaVersion: 8 },
errors: [{ message: "Missing space before function parentheses.", type: "ArrowFunctionExpression" }]
},
{
code: "async () => 1",
output: "async() => 1",
options: ["never"],
parserOptions: { ecmaVersion: 8 },
errors: [{ message: "Unexpected space before function parentheses.", type: "ArrowFunctionExpression" }]
}
]
});

0 comments on commit 7dd890d

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