forked from qunitjs/eslint-plugin-qunit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathno-global-expect.js
More file actions
58 lines (51 loc) · 2.06 KB
/
no-global-expect.js
File metadata and controls
58 lines (51 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/**
* @fileoverview Forbid the use of global expect.
* @author Kevin Partington
*/
"use strict";
//------------------------------------------------------------------------------
// Requirements
//------------------------------------------------------------------------------
const { ReferenceTracker } = require("@eslint-community/eslint-utils");
//------------------------------------------------------------------------------
// Rule Definition
//------------------------------------------------------------------------------
/** @type {import('eslint').Rule.RuleModule} */
module.exports = {
meta: {
type: "suggestion",
docs: {
description: "disallow global expect",
category: "Possible Errors",
url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/main/docs/rules/no-global-expect.md",
},
messages: {
unexpectedGlobalExpect: "Unexpected global expect.",
},
schema: [],
},
create: function (context) {
return {
Program: function (node) {
/* istanbul ignore next: deprecated code paths only followed by old eslint versions */
const sourceCode =
context.sourceCode ?? context.getSourceCode();
/* istanbul ignore next: deprecated code paths only followed by old eslint versions */
const scope = sourceCode.getScope
? sourceCode.getScope(node)
: // @ts-expect-error -- removed in ESLint 10, but needed for ESLint 8 compat
context.getScope();
const tracker = new ReferenceTracker(scope);
const traceMap = { expect: { [ReferenceTracker.CALL]: true } };
for (const { node } of tracker.iterateGlobalReferences(
traceMap,
)) {
context.report({
node: node,
messageId: "unexpectedGlobalExpect",
});
}
},
};
},
};