Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ignore more types in
no-fn-reference-in-iterator
and no-reduce
ru…
…le (#756)
- Loading branch information
Showing
6 changed files
with
135 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
'use strict'; | ||
|
||
// AST Types: | ||
// https://github.com/eslint/espree/blob/master/lib/ast-node-types.js#L18 | ||
// Only types possible to be `argument` are listed | ||
const impossibleNodeTypes = [ | ||
'ArrayExpression', | ||
'BinaryExpression', | ||
'ClassExpression', | ||
'Literal', | ||
'ObjectExpression', | ||
'TemplateLiteral', | ||
'UnaryExpression', | ||
'UpdateExpression' | ||
]; | ||
|
||
// Technically these nodes could be a function, but most likely not | ||
const mostLikelyNotNodeTypes = [ | ||
'AssignmentExpression', | ||
'AwaitExpression', | ||
'CallExpression', | ||
'LogicalExpression', | ||
'NewExpression', | ||
'TaggedTemplateExpression', | ||
'ThisExpression' | ||
]; | ||
|
||
const notFunctionSelector = node => [ | ||
...[...impossibleNodeTypes, ...mostLikelyNotNodeTypes].map(type => `[${node}.type!="${type}"]`), | ||
`:not([${node}.type="Identifier"][${node}.name="undefined"])` | ||
].join(''); | ||
|
||
module.exports = { | ||
notFunctionSelector | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
'use strict'; | ||
|
||
module.exports = [ | ||
// ArrayExpression | ||
'[]', | ||
'[element]', | ||
'[...elements]', | ||
// BinaryExpression | ||
'1 + fn', | ||
'"length" in fn', | ||
'fn instanceof Function', | ||
// ClassExpression | ||
'class ClassCantUseAsFunction {}', | ||
// Literal | ||
'0', | ||
'1', | ||
'0.1', | ||
'""', | ||
'"string"', | ||
'/regex/', | ||
'null', | ||
'0n', | ||
'1n', | ||
'true', | ||
'false', | ||
// ObjectExpression | ||
'{}', | ||
// TemplateLiteral | ||
'`templateLiteral`', | ||
// Undefined | ||
'undefined', | ||
// UnaryExpression | ||
'- fn', | ||
'+ fn', | ||
'~ fn', | ||
'typeof fn', | ||
'void fn', | ||
'delete fn', | ||
// UpdateExpression | ||
'++ fn', | ||
'-- fn', | ||
|
||
// Following are not safe | ||
'a = fn', // Could be a function | ||
// 'await fn', // This requires async function to test, ignore for now | ||
'fn()', // Could be a factory returns a function | ||
'fn1 || fn2', // Could be a function | ||
'new ClassReturnsFunction()', // `class` constructor could return a function | ||
'new Function()', // `function` | ||
'fn``', // Same as `CallExpression` | ||
'this' // Could be a function | ||
]; |