Skip to content

Commit

Permalink
Fix invalid syntax in test case
Browse files Browse the repository at this point in the history
new.target is only allowed in functions
I’ve also removed the unnecessary if statement in the rule as we can’t
test the else branch because it is unreachable.
  • Loading branch information
lo1tuma committed Oct 26, 2018
1 parent 8ad5267 commit 798efa0
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 16 deletions.
17 changes: 2 additions & 15 deletions lib/rules/prefer-arrow-callback.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,6 @@ function isFunctionName(variable) {
return variable && variable.defs[0].type === 'FunctionName';
}

/**
* Checks whether or not a given MetaProperty node equals to a given value.
* @param {ASTNode} node - A MetaProperty node to check.
* @param {string} metaName - The name of `MetaProperty.meta`.
* @param {string} propertyName - The name of `MetaProperty.property`.
* @returns {boolean} `true` if the node is the specific value.
*/
function checkMetaProperty(node, metaName, propertyName) {
return node.meta.name === metaName && node.property.name === propertyName;
}

/**
* Gets the variable object of `arguments` which is defined implicitly.
* @param {eslint-scope.Scope} scope - A scope to get.
Expand Down Expand Up @@ -245,12 +234,10 @@ module.exports = {
}
},

MetaProperty(node) {
MetaProperty() {
const info = stack[stack.length - 1];

if (info && checkMetaProperty(node, 'new', 'target')) {
info.meta = true;
}
info.meta = true;
},

// To skip nested scopes.
Expand Down
1 change: 0 additions & 1 deletion test/rules/prefer-arrow-callback.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ ruleTester.run('prefer-arrow-callback', rules['prefer-arrow-callback'], {
'() => super()',
'foo(function bar() { new.target; });',
'foo(function bar() { new.target; }.bind(this));',
'() => new.target',
'foo(function bar() { this; }.bind(this, somethingElse));',
// mocha-specific valid test cases
'before(function bar() {});',
Expand Down

0 comments on commit 798efa0

Please sign in to comment.