Skip to content

Commit

Permalink
Breaking: tweak space-before-function-paren default option (fixes #8267)
Browse files Browse the repository at this point in the history
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 committed Mar 18, 2017
1 parent 8976c7f commit 5a16c87
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
4 changes: 1 addition & 3 deletions lib/rules/space-before-function-paren.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
25 changes: 20 additions & 5 deletions tests/lib/rules/space-before-function-paren.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,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 } }
],

Expand Down Expand Up @@ -489,6 +484,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 5a16c87

Please sign in to comment.