Skip to content

Commit a3dd6c2

Browse files
committed
fix(no-jasmine-globals): Fix false positives for pending/fail/spyOn
Prior to this, similarly named local variables & parameters would trigger the no-jasmine-globals warning Fixes #156
1 parent 6eabb5c commit a3dd6c2

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

rules/__tests__/no-jasmine-globals.test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ ruleTester.run('no-jasmine-globals', rule, {
1515
'test("foo", function () {})',
1616
'foo()',
1717
`require('foo')('bar')`,
18+
'function callback(fail) { fail() }',
19+
'var spyOn = require("actions"); spyOn("foo")',
20+
'function callback(pending) { pending() }',
1821
],
1922
invalid: [
2023
{

rules/no-jasmine-globals.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use strict';
22

3-
const { getDocsUrl, getNodeName } = require('./util');
3+
const { getDocsUrl, getNodeName, scopeHasLocalReference } = require('./util');
44

55
const globalAlternatives = {
66
spyOn: 'Illegal usage of global `spyOn`, prefer `jest.spyOn`',
@@ -32,6 +32,11 @@ module.exports = {
3232
calleeName === 'fail' ||
3333
calleeName === 'pending'
3434
) {
35+
if (scopeHasLocalReference(context.getScope(), calleeName)) {
36+
// It's a local variable, not a jasmine global.
37+
return;
38+
}
39+
3540
context.report({
3641
node,
3742
message: globalAlternatives[calleeName],

0 commit comments

Comments
 (0)