| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -66,7 +66,7 @@ new RuleTester({ | |||
| 66 | 66 | }, | |
| 67 | 67 | { | |
| 68 | 68 | code: 'const { NumberParseInt } = primordials; NumberParseInt("xxx")', | |
| 69 | - options: [{ name: 'parseInt' }] | ||
| 69 | + options: [{ name: 'parseInt', into: 'Number' }] | ||
| 70 | 70 | }, | |
| 71 | 71 | { | |
| 72 | 72 | code: ` | |
@@ -141,7 +141,7 @@ new RuleTester({ | |||
| 141 | 141 | const { Number } = primordials; | |
| 142 | 142 | Number.parseInt('10') | |
| 143 | 143 | `, | |
| 144 | - options: [{ name: 'Number', into: Number }], | ||
| 144 | + options: [{ name: 'Number' }], | ||
| 145 | 145 | errors: [{ message: /const { NumberParseInt } = primordials/ }] | |
| 146 | 146 | }, | |
| 147 | 147 | { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -23,10 +23,7 @@ function isTarget(map, varName) { | |||
| 23 | 23 | } | |
| 24 | 24 | ||
| 25 | 25 | function isIgnored(map, varName, propName) { | |
| 26 | - if (!map.has(varName) || !map.get(varName).has(propName)) { | ||
| 27 | - return false; | ||
| 28 | - } | ||
| 29 | - return map.get(varName).get(propName).ignored; | ||
| 26 | + return map.get(varName)?.get(propName)?.ignored ?? false; | ||
| 30 | 27 | } | |
| 31 | 28 | ||
| 32 | 29 | function getReportName({ name, parentName, into }) { | |
@@ -71,25 +68,26 @@ module.exports = { | |||
| 71 | 68 | }, | |
| 72 | 69 | create(context) { | |
| 73 | 70 | const globalScope = context.getSourceCode().scopeManager.globalScope; | |
| 74 | - const nameMap = context.options.reduce((acc, option) => | ||
| 75 | - acc.set( | ||
| 71 | + | ||
| 72 | + const nameMap = new Map(); | ||
| 73 | + const renameMap = new Map(); | ||
| 74 | + | ||
| 75 | + for (const option of context.options) { | ||
| 76 | + const names = option.ignore || []; | ||
| 77 | + nameMap.set( | ||
| 76 | 78 | option.name, | |
| 77 | - (option.ignore || []) | ||
| 78 | - .reduce((acc, name) => acc.set(name, { | ||
| 79 | - ignored: true | ||
| 80 | - }), new Map()) | ||
| 81 | - ) | ||
| 82 | - , new Map()); | ||
| 83 | - const renameMap = context.options | ||
| 84 | - .filter((option) => option.into) | ||
| 85 | - .reduce((acc, option) => | ||
| 86 | - acc.set(option.name, option.into) | ||
| 87 | - , new Map()); | ||
| 79 | + new Map(names.map((name) => [name, { ignored: true }])) | ||
| 80 | + ); | ||
| 81 | + if (option.into) { | ||
| 82 | + renameMap.set(option.name, option.into); | ||
| 83 | + } | ||
| 84 | + } | ||
| 85 | + | ||
| 88 | 86 | let reported; | |
| 89 | 87 | ||
| 90 | 88 | return { | |
| 91 | 89 | Program() { | |
| 92 | - reported = new Map(); | ||
| 90 | + reported = new Set(); | ||
| 93 | 91 | }, | |
| 94 | 92 | [identifierSelector](node) { | |
| 95 | 93 | if (reported.has(node.range[0])) { | |
@@ -104,10 +102,10 @@ module.exports = { | |||
| 104 | 102 | return; | |
| 105 | 103 | } | |
| 106 | 104 | ||
| 107 | - const defs = (globalScope.set.get(name) || {}).defs || null; | ||
| 105 | + const defs = globalScope.set.get(name)?.defs; | ||
| 108 | 106 | if (parentName && isTarget(nameMap, parentName)) { | |
| 109 | 107 | if (!defs || defs[0].name.name !== 'primordials') { | |
| 110 | - reported.set(node.range[0], true); | ||
| 108 | + reported.add(node.range[0]); | ||
| 111 | 109 | const into = renameMap.get(name); | |
| 112 | 110 | context.report({ | |
| 113 | 111 | node, | |
@@ -120,7 +118,7 @@ module.exports = { | |||
| 120 | 118 | return; | |
| 121 | 119 | } | |
| 122 | 120 | if (defs.length === 0 || defs[0].node.init.name !== 'primordials') { | |
| 123 | - reported.set(node.range[0], true); | ||
| 121 | + reported.add(node.range[0]); | ||
| 124 | 122 | const into = renameMap.get(name); | |
| 125 | 123 | context.report({ | |
| 126 | 124 | node, | |
| Back | FazBrowse Home | New Git URL |
0 commit comments