| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 4fbe064 commit 98167e8
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -99,6 +99,34 @@ new RuleTester({ | |||
| 99 | 99 | `, | |
| 100 | 100 | options: [{ name: 'Function' }], | |
| 101 | 101 | }, | |
| 102 | + { | ||
| 103 | + code: 'function identifier() {}', | ||
| 104 | + options: [{ name: 'identifier' }] | ||
| 105 | + }, | ||
| 106 | + { | ||
| 107 | + code: 'function* identifier() {}', | ||
| 108 | + options: [{ name: 'identifier' }] | ||
| 109 | + }, | ||
| 110 | + { | ||
| 111 | + code: 'class identifier {}', | ||
| 112 | + options: [{ name: 'identifier' }] | ||
| 113 | + }, | ||
| 114 | + { | ||
| 115 | + code: 'new class { identifier(){} }', | ||
| 116 | + options: [{ name: 'identifier' }] | ||
| 117 | + }, | ||
| 118 | + { | ||
| 119 | + code: 'const a = { identifier: \'4\' }', | ||
| 120 | + options: [{ name: 'identifier' }] | ||
| 121 | + }, | ||
| 122 | + { | ||
| 123 | + code: 'identifier:{const a = 4}', | ||
| 124 | + options: [{ name: 'identifier' }] | ||
| 125 | + }, | ||
| 126 | + { | ||
| 127 | + code: 'switch(0){case identifier:}', | ||
| 128 | + options: [{ name: 'identifier' }] | ||
| 129 | + }, | ||
| 102 | 130 | ], | |
| 103 | 131 | invalid: [ | |
| 104 | 132 | { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -57,8 +57,18 @@ function getDestructuringAssignmentParent(scope, node) { | |||
| 57 | 57 | return declaration.defs[0].node.init; | |
| 58 | 58 | } | |
| 59 | 59 | ||
| 60 | - const identifierSelector = | ||
| 61 | - '[type!=VariableDeclarator][type!=MemberExpression]>Identifier'; | ||
| 60 | + const parentSelectors = [ | ||
| 61 | + // We want to select identifiers that refer to other references, not the ones | ||
| 62 | + // that create a new reference. | ||
| 63 | + 'ClassDeclaration', | ||
| 64 | + 'FunctionDeclaration', | ||
| 65 | + 'LabeledStatement', | ||
| 66 | + 'MemberExpression', | ||
| 67 | + 'MethodDefinition', | ||
| 68 | + 'SwitchCase', | ||
| 69 | + 'VariableDeclarator', | ||
| 70 | + ]; | ||
| 71 | + const identifierSelector = parentSelectors.map((selector) => `[type!=${selector}]`).join('') + '>Identifier'; | ||
| 62 | 72 | ||
| 63 | 73 | module.exports = { | |
| 64 | 74 | meta: { | |
@@ -90,6 +100,11 @@ module.exports = { | |||
| 90 | 100 | reported = new Set(); | |
| 91 | 101 | }, | |
| 92 | 102 | [identifierSelector](node) { | |
| 103 | + if (node.parent.type === 'Property' && node.parent.key === node) { | ||
| 104 | + // If the identifier is the key for this property declaration, it | ||
| 105 | + // can't be referring to a primordials member. | ||
| 106 | + return; | ||
| 107 | + } | ||
| 93 | 108 | if (reported.has(node.range[0])) { | |
| 94 | 109 | return; | |
| 95 | 110 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments