eslint-plugin-inker
Advanced tools
Comparing version 2.5.4 to 2.5.5
@@ -8,10 +8,2 @@ "use strict"; | ||
create(context) { | ||
const isVariableNameTaken = (name) => { | ||
const scope = context.getScope(); | ||
return scope.variables.some(variable => variable.name === name); | ||
}; | ||
const getVariableUsages = (name) => { | ||
const scope = context.getScope(); | ||
return scope.references.filter(ref => ref.identifier.name === name); | ||
}; | ||
return { | ||
@@ -35,3 +27,5 @@ VariableDeclarator(node) { | ||
const suggestedName = `${id.name}Ref`; | ||
const suggest = isVariableNameTaken(suggestedName) | ||
const scope = context.getScope(); | ||
const isNameTaken = scope.variables.some(variable => variable.name === suggestedName); | ||
const suggest = isNameTaken | ||
? undefined | ||
@@ -42,6 +36,7 @@ : [ | ||
fix(fixer) { | ||
const usages = getVariableUsages(id.name); | ||
const referenceIdentifiers = usages.map(ref => ref.identifier); | ||
var _a, _b; | ||
const references = (_b = (_a = context.getDeclaredVariables(node)[0]) === null || _a === void 0 ? void 0 : _a.references) !== null && _b !== void 0 ? _b : []; | ||
const referenceIdentifiers = references.map(ref => ref.identifier); | ||
return [ | ||
// id, | ||
id, | ||
...referenceIdentifiers, | ||
@@ -48,0 +43,0 @@ ].map(identifier => fixer.replaceText(identifier, suggestedName)); |
{ | ||
"name": "eslint-plugin-inker", | ||
"version": "2.5.4", | ||
"version": "2.5.5", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "types": "dist/index.d.ts", |
@@ -12,12 +12,2 @@ // eslint-disable-next-line import/no-extraneous-dependencies | ||
create(context) { | ||
const isVariableNameTaken = (name: string) => { | ||
const scope = context.getScope() | ||
return scope.variables.some(variable => variable.name === name) | ||
} | ||
const getVariableUsages = (name: string) => { | ||
const scope = context.getScope() | ||
return scope.references.filter(ref => ref.identifier.name === name) | ||
} | ||
return { | ||
@@ -50,5 +40,7 @@ VariableDeclarator(node) { | ||
const scope = context.getScope() | ||
const isNameTaken = scope.variables.some(variable => variable.name === suggestedName) | ||
type Suggest = Parameters<typeof context.report>[0]['suggest'] | ||
const suggest: Suggest = isVariableNameTaken(suggestedName) | ||
const suggest: Suggest = isNameTaken | ||
? undefined | ||
@@ -59,6 +51,6 @@ : [ | ||
fix(fixer) { | ||
const usages = getVariableUsages(id.name) | ||
const referenceIdentifiers = usages.map(ref => ref.identifier) | ||
const references = context.getDeclaredVariables(node)[0]?.references ?? [] | ||
const referenceIdentifiers = references.map(ref => ref.identifier) | ||
return [ | ||
// id, | ||
id, | ||
...referenceIdentifiers, | ||
@@ -65,0 +57,0 @@ ].map(identifier => fixer.replaceText(identifier, suggestedName)) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
46223
1327