| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 95e4d29 commit 50d102e
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -81,6 +81,23 @@ new RuleTester({ | |||
| 81 | 81 | code: 'const { Map } = primordials; new Map()', | |
| 82 | 82 | options: [{ name: 'Map', into: 'Safe' }], | |
| 83 | 83 | }, | |
| 84 | + { | ||
| 85 | + code: ` | ||
| 86 | + const { Function } = primordials; | ||
| 87 | + const rename = Function; | ||
| 88 | + const obj = { rename }; | ||
| 89 | + `, | ||
| 90 | + options: [{ name: 'Function' }], | ||
| 91 | + }, | ||
| 92 | + { | ||
| 93 | + code: ` | ||
| 94 | + const { Function } = primordials; | ||
| 95 | + let rename; | ||
| 96 | + rename = Function; | ||
| 97 | + const obj = { rename }; | ||
| 98 | + `, | ||
| 99 | + options: [{ name: 'Function' }], | ||
| 100 | + }, | ||
| 84 | 101 | ], | |
| 85 | 102 | invalid: [ | |
| 86 | 103 | { | |
@@ -158,6 +175,16 @@ new RuleTester({ | |||
| 158 | 175 | options: [{ name: 'Reflect' }], | |
| 159 | 176 | errors: [{ message: /const { ReflectOwnKeys } = primordials/ }] | |
| 160 | 177 | }, | |
| 178 | + { | ||
| 179 | + code: ` | ||
| 180 | + const { Reflect } = primordials; | ||
| 181 | + module.exports = function() { | ||
| 182 | + const { ownKeys } = Reflect; | ||
| 183 | + } | ||
| 184 | + `, | ||
| 185 | + options: [{ name: 'Reflect' }], | ||
| 186 | + errors: [{ message: /const { ReflectOwnKeys } = primordials/ }] | ||
| 187 | + }, | ||
| 161 | 188 | { | |
| 162 | 189 | code: 'new Map()', | |
| 163 | 190 | options: [{ name: 'Map', into: 'Safe' }], | |
@@ -171,5 +198,36 @@ new RuleTester({ | |||
| 171 | 198 | options: [{ name: 'Function' }], | |
| 172 | 199 | errors: [{ message: /const { FunctionPrototype } = primordials/ }] | |
| 173 | 200 | }, | |
| 201 | + { | ||
| 202 | + code: ` | ||
| 203 | + const obj = { Function }; | ||
| 204 | + `, | ||
| 205 | + options: [{ name: 'Function' }], | ||
| 206 | + errors: [{ message: /const { Function } = primordials/ }] | ||
| 207 | + }, | ||
| 208 | + { | ||
| 209 | + code: ` | ||
| 210 | + const rename = Function; | ||
| 211 | + `, | ||
| 212 | + options: [{ name: 'Function' }], | ||
| 213 | + errors: [{ message: /const { Function } = primordials/ }] | ||
| 214 | + }, | ||
| 215 | + { | ||
| 216 | + code: ` | ||
| 217 | + const rename = Function; | ||
| 218 | + const obj = { rename }; | ||
| 219 | + `, | ||
| 220 | + options: [{ name: 'Function' }], | ||
| 221 | + errors: [{ message: /const { Function } = primordials/ }] | ||
| 222 | + }, | ||
| 223 | + { | ||
| 224 | + code: ` | ||
| 225 | + let rename; | ||
| 226 | + rename = Function; | ||
| 227 | + const obj = { rename }; | ||
| 228 | + `, | ||
| 229 | + options: [{ name: 'Function' }], | ||
| 230 | + errors: [{ message: /const { Function } = primordials/ }] | ||
| 231 | + }, | ||
| 174 | 232 | ] | |
| 175 | 233 | }); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -54,7 +54,7 @@ function getDestructuringAssignmentParent(scope, node) { | |||
| 54 | 54 | ) { | |
| 55 | 55 | return null; | |
| 56 | 56 | } | |
| 57 | - return declaration.defs[0].node.init.name; | ||
| 57 | + return declaration.defs[0].node.init; | ||
| 58 | 58 | } | |
| 59 | 59 | ||
| 60 | 60 | const identifierSelector = | |
@@ -94,17 +94,20 @@ module.exports = { | |||
| 94 | 94 | return; | |
| 95 | 95 | } | |
| 96 | 96 | const name = node.name; | |
| 97 | - const parentName = getDestructuringAssignmentParent( | ||
| 97 | + const parent = getDestructuringAssignmentParent( | ||
| 98 | 98 | context.getScope(), | |
| 99 | 99 | node | |
| 100 | 100 | ); | |
| 101 | + const parentName = parent?.name; | ||
| 101 | 102 | if (!isTarget(nameMap, name) && !isTarget(nameMap, parentName)) { | |
| 102 | 103 | return; | |
| 103 | 104 | } | |
| 104 | 105 | ||
| 105 | 106 | const defs = globalScope.set.get(name)?.defs; | |
| 106 | 107 | if (parentName && isTarget(nameMap, parentName)) { | |
| 107 | - if (!defs || defs[0].name.name !== 'primordials') { | ||
| 108 | + if (defs?.[0].name.name !== 'primordials' && | ||
| 109 | + !reported.has(parent.range[0]) && | ||
| 110 | + parent.parent?.id?.type !== 'Identifier') { | ||
| 108 | 111 | reported.add(node.range[0]); | |
| 109 | 112 | const into = renameMap.get(name); | |
| 110 | 113 | context.report({ | |
@@ -147,7 +150,20 @@ module.exports = { | |||
| 147 | 150 | } | |
| 148 | 151 | }); | |
| 149 | 152 | } | |
| 150 | - } | ||
| 153 | + }, | ||
| 154 | + VariableDeclarator(node) { | ||
| 155 | + const name = node.init?.name; | ||
| 156 | + if (name !== undefined && isTarget(nameMap, name) && | ||
| 157 | + node.id.type === 'Identifier' && | ||
| 158 | + !globalScope.set.get(name)?.defs.length) { | ||
| 159 | + reported.add(node.init.range[0]); | ||
| 160 | + context.report({ | ||
| 161 | + node, | ||
| 162 | + messageId: 'error', | ||
| 163 | + data: { name }, | ||
| 164 | + }); | ||
| 165 | + } | ||
| 166 | + }, | ||
| 151 | 167 | }; | |
| 152 | 168 | } | |
| 153 | 169 | }; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments