Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorAntoine du Hamel <duhamelantoine1995@gmail.com>2022-02-18 21:42:02 +0300
committerGitHub <noreply@github.com>2022-02-18 21:42:02 +0300
commit6700b5c9e114d507f3e5425e4da3ca5724d3e23c (patch)
tree472be282ba6218f3c5ba1233e67e58d24dd0b40b /tools
parent68c4b8d56d653a77747648b933618ade63bf2007 (diff)
tools: fix bugs in prefer-primordials linter rule
The ESLint rule would repport false positive if code is using an identifier that happens to have the same name as a primordials member. PR-URL: https://github.com/nodejs/node/pull/42010 Reviewed-By: Shingo Inoue <leko.noor@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'tools')
-rw-r--r--tools/eslint-rules/prefer-primordials.js19
1 files changed, 17 insertions, 2 deletions
diff --git a/tools/eslint-rules/prefer-primordials.js b/tools/eslint-rules/prefer-primordials.js
index 7ddff539640..d2531556de2 100644
--- a/tools/eslint-rules/prefer-primordials.js
+++ b/tools/eslint-rules/prefer-primordials.js
@@ -57,8 +57,18 @@ function getDestructuringAssignmentParent(scope, node) {
return declaration.defs[0].node.init;
}
-const identifierSelector =
- '[type!=VariableDeclarator][type!=MemberExpression]>Identifier';
+const parentSelectors = [
+ // We want to select identifiers that refer to other references, not the ones
+ // that create a new reference.
+ 'ClassDeclaration',
+ 'FunctionDeclaration',
+ 'LabeledStatement',
+ 'MemberExpression',
+ 'MethodDefinition',
+ 'SwitchCase',
+ 'VariableDeclarator',
+];
+const identifierSelector = parentSelectors.map((selector) => `[type!=${selector}]`).join('') + '>Identifier';
module.exports = {
meta: {
@@ -90,6 +100,11 @@ module.exports = {
reported = new Set();
},
[identifierSelector](node) {
+ if (node.parent.type === 'Property' && node.parent.key === node) {
+ // If the identifier is the key for this property declaration, it
+ // can't be referring to a primordials member.
+ return;
+ }
if (reported.has(node.range[0])) {
return;
}