Skip to content

Commit

Permalink
Fix: space-before-function-parentheses generator methods (fixes #2082)
Browse files Browse the repository at this point in the history
  • Loading branch information
btmills committed Mar 16, 2015
1 parent d0edc11 commit e95825b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
10 changes: 8 additions & 2 deletions lib/rules/space-before-function-parentheses.js
Expand Up @@ -75,8 +75,14 @@ module.exports = function(context) {
tokens = context.getTokens(node);

if (node.generator) {
leftToken = tokens[2];
rightToken = tokens[3];
if (node.id) {
leftToken = tokens[2];
rightToken = tokens[3];
} else {
// Object methods are named but don't have an id
leftToken = context.getTokenBefore(node);
rightToken = tokens[0];
}
} else if (isNamed) {
if (node.id) {
leftToken = tokens[1];
Expand Down
23 changes: 19 additions & 4 deletions tests/lib/rules/space-before-function-parentheses.js
Expand Up @@ -80,10 +80,19 @@ eslintTester.addRuleTest("lib/rules/space-before-function-parentheses", {
}
},
{
code: "class Foo { constructor() {} }",
code: "class Foo { constructor() {} *method() {} }",
options: [ { named: "never", anonymous: "always" } ],
ecmaFeatures: {
classes: true
classes: true,
generators: true
}
},
{
code: "class Foo { constructor () {} *method () {} }",
options: [ { named: "always", anonymous: "never" } ],
ecmaFeatures: {
classes: true,
generators: true
}
}
],
Expand Down Expand Up @@ -287,15 +296,21 @@ eslintTester.addRuleTest("lib/rules/space-before-function-parentheses", {
]
},
{
code: "class Foo { constructor () {} }",
code: "class Foo { constructor () {} *method () {} }",
options: [ { named: "never", anonymous: "always" } ],
ecmaFeatures: { classes: true },
ecmaFeatures: { classes: true, generators: true },
errors: [
{
type: "FunctionExpression",
message: "Unexpected space before function parentheses.",
line: 1,
column: 23
},
{
type: "FunctionExpression",
message: "Unexpected space before function parentheses.",
line: 1,
column: 37
}
]
},
Expand Down

0 comments on commit e95825b

Please sign in to comment.