-
Notifications
You must be signed in to change notification settings - Fork 236
/
no-jest-import.js
40 lines (38 loc) · 1008 Bytes
/
no-jest-import.js
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
'use strict';
const getDocsUrl = require('./util').getDocsUrl;
const getNodeName = require('./util').getNodeName;
const message = `Jest is automatically in scope. Do not import "jest", as Jest doesn't export anything.`;
module.exports = {
meta: {
docs: {
url: getDocsUrl(__filename),
},
},
create(context) {
return {
ImportDeclaration(node) {
if (node.source.value === 'jest') {
context.report({
node,
message,
});
}
},
CallExpression(node) {
const calleeName = getNodeName(node.callee);
if (calleeName === 'require' && node.arguments[0].value === 'jest') {
context.report({
loc: {
end: {
column: node.arguments[0].loc.end.column,
line: node.arguments[0].loc.end.line,
},
start: node.arguments[0].loc.start,
},
message,
});
}
},
};
},
};