eslint-plugin-jest
Advanced tools
Comparing version 27.1.4 to 27.1.5
@@ -71,3 +71,3 @@ "use strict"; | ||
'CallExpression[callee.name="pending"]'(node) { | ||
if ((0, _utils.scopeHasLocalReference)(context.getScope(), 'pending')) { | ||
if ((0, _utils.resolveScope)(context.getScope(), 'pending')) { | ||
return; | ||
@@ -74,0 +74,0 @@ } |
@@ -40,3 +40,3 @@ "use strict"; | ||
if (calleeName === 'spyOn' || calleeName === 'spyOnProperty' || calleeName === 'fail' || calleeName === 'pending') { | ||
if ((0, _utils2.scopeHasLocalReference)(context.getScope(), calleeName)) { | ||
if ((0, _utils2.resolveScope)(context.getScope(), calleeName)) { | ||
// It's a local variable, not a jasmine global. | ||
@@ -43,0 +43,0 @@ return; |
@@ -7,3 +7,3 @@ "use strict"; | ||
exports.getNodeChain = getNodeChain; | ||
exports.scopeHasLocalReference = exports.parseJestFnCallWithReason = exports.parseJestFnCall = exports.isTypeOfJestFnCall = void 0; | ||
exports.resolveScope = exports.parseJestFnCallWithReason = exports.parseJestFnCall = exports.isTypeOfJestFnCall = void 0; | ||
var _utils = require("@typescript-eslint/utils"); | ||
@@ -290,38 +290,7 @@ var _utils2 = require("../utils"); | ||
}; | ||
const collectReferences = scope => { | ||
const locals = new Set(); | ||
const imports = new Map(); | ||
const unresolved = new Set(); | ||
let currentScope = scope; | ||
while (currentScope !== null) { | ||
for (const ref of currentScope.variables) { | ||
if (ref.defs.length === 0) { | ||
continue; | ||
} | ||
const def = ref.defs[ref.defs.length - 1]; | ||
const importDetails = describePossibleImportDef(def); | ||
if (importDetails) { | ||
imports.set(importDetails.local, importDetails); | ||
continue; | ||
} | ||
locals.add(ref.name); | ||
} | ||
for (const ref of currentScope.through) { | ||
unresolved.add(ref.identifier.name); | ||
} | ||
currentScope = currentScope.upper; | ||
} | ||
return { | ||
locals, | ||
imports, | ||
unresolved | ||
}; | ||
}; | ||
const resolveScope = (scope, identifier) => { | ||
let currentScope = scope; | ||
while (currentScope !== null) { | ||
for (const ref of currentScope.variables) { | ||
if (ref.defs.length === 0) { | ||
continue; | ||
} | ||
const ref = currentScope.set.get(identifier); | ||
if (ref && ref.defs.length > 0) { | ||
const def = ref.defs[ref.defs.length - 1]; | ||
@@ -332,5 +301,3 @@ const importDetails = describePossibleImportDef(def); | ||
} | ||
if (ref.name === identifier) { | ||
return 'local'; | ||
} | ||
return 'local'; | ||
} | ||
@@ -341,2 +308,3 @@ currentScope = currentScope.upper; | ||
}; | ||
exports.resolveScope = resolveScope; | ||
const resolveToJestFn = (context, identifier) => { | ||
@@ -367,15 +335,2 @@ const maybeImport = resolveScope(context.getScope(), identifier); | ||
}; | ||
}; | ||
const scopeHasLocalReference = (scope, referenceName) => { | ||
const references = collectReferences(scope); | ||
return ( | ||
// referenceName was found as a local variable or function declaration. | ||
references.locals.has(referenceName) || | ||
// referenceName was found as an imported identifier | ||
references.imports.has(referenceName) || | ||
// referenceName was not found as an unresolved reference, | ||
// meaning it is likely not an implicit global reference. | ||
!references.unresolved.has(referenceName) | ||
); | ||
}; | ||
exports.scopeHasLocalReference = scopeHasLocalReference; | ||
}; |
@@ -9,3 +9,3 @@ "use strict"; | ||
var _utils2 = require("./utils"); | ||
const trimFXprefix = word => ['f', 'x'].includes(word.charAt(0)) ? word.substr(1) : word; | ||
const trimFXprefix = word => ['f', 'x'].includes(word.charAt(0)) ? word.substring(1) : word; | ||
const doesBinaryExpressionContainStringNode = binaryExp => { | ||
@@ -12,0 +12,0 @@ if ((0, _utils2.isStringNode)(binaryExp.right)) { |
{ | ||
"name": "eslint-plugin-jest", | ||
"version": "27.1.4", | ||
"version": "27.1.5", | ||
"description": "ESLint rules for Jest", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
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
310498
5259