forked from qunitjs/eslint-plugin-qunit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathno-global-module-test.js
More file actions
71 lines (64 loc) · 2.61 KB
/
no-global-module-test.js
File metadata and controls
71 lines (64 loc) · 2.61 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
59
60
61
62
63
64
65
66
67
68
69
70
71
/**
* @fileoverview Forbid the use of global module/test/asyncTest.
* @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 module/test/asyncTest",
category: "Possible Errors",
url: "https://github.com/platinumazure/eslint-plugin-qunit/blob/main/docs/rules/no-global-module-test.md",
},
messages: {
unexpectedGlobalModuleTest: "Unexpected global `{{ callee }}`.",
},
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 = {
asyncTest: { [ReferenceTracker.CALL]: true },
module: { [ReferenceTracker.CALL]: true },
test: { [ReferenceTracker.CALL]: true },
};
for (const { node } of tracker.iterateGlobalReferences(
traceMap,
)) {
if (node.type !== "CallExpression") {
continue;
}
if (node.callee.type !== "Identifier") {
continue;
}
context.report({
node: node,
messageId: "unexpectedGlobalModuleTest",
data: {
callee: node.callee.name,
},
});
}
},
};
},
};