Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
179 additions
and
41 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
'use strict'; | ||
|
||
const enforceNew = [ | ||
'Object', | ||
'Array', | ||
'ArrayBuffer', | ||
'BigInt64Array', | ||
'BigUint64Array', | ||
'DataView', | ||
'Date', | ||
'Error', | ||
'Float32Array', | ||
'Float64Array', | ||
'Function', | ||
'Int8Array', | ||
'Int16Array', | ||
'Int32Array', | ||
'Map', | ||
'WeakMap', | ||
'Set', | ||
'WeakSet', | ||
'Promise', | ||
'RegExp', | ||
'Uint8Array', | ||
'Uint16Array', | ||
'Uint32Array', | ||
'Uint8ClampedArray' | ||
]; | ||
|
||
const disallowNew = [ | ||
'BigInt', | ||
'Boolean', | ||
'Number', | ||
'String', | ||
'Symbol' | ||
]; | ||
|
||
module.exports = { | ||
enforceNew, | ||
disallowNew | ||
}; |
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'; | ||
|
||
/** | ||
* Finds the eslint-scope reference in the given scope. | ||
* @param {Object} scope The scope to search. | ||
* @param {ASTNode} node The identifier node. | ||
* @returns {Reference|undefined} Returns the found reference or null if none were found. | ||
*/ | ||
function findReference(scope, node) { | ||
const references = scope.references | ||
.filter(reference => | ||
reference.identifier.range[0] === node.range[0] && | ||
reference.identifier.range[1] === node.range[1] | ||
); | ||
|
||
return references.length === 1 ? references[0] : undefined; | ||
} | ||
|
||
/** | ||
* Checks if the given identifier node is shadowed in the given scope. | ||
* @param {Object} scope The current scope. | ||
* @param {string} node The identifier node to check | ||
* @returns {boolean} Whether or not the name is shadowed. | ||
*/ | ||
function isShadowed(scope, node) { | ||
const reference = findReference(scope, node); | ||
|
||
return ( | ||
reference && | ||
reference.resolved && | ||
reference.resolved.defs.length > 0 | ||
); | ||
} | ||
|
||
module.exports = isShadowed; |
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