Skip to content

Commit

Permalink
refactor(no-jest-import): use ESQuery syntax for selectors (#158)
Browse files Browse the repository at this point in the history
  • Loading branch information
macklinu authored and SimenB committed Oct 1, 2018
1 parent f2d2dbe commit 2a1ae17
Showing 1 changed file with 8 additions and 26 deletions.
34 changes: 8 additions & 26 deletions rules/no-jest-import.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'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 = {
Expand All @@ -12,32 +12,14 @@ module.exports = {
},
create(context) {
return {
ImportDeclaration(node) {
if (node.source.value === 'jest') {
context.report({
node,
message,
});
}
'ImportDeclaration[source.value="jest"]'(node) {
context.report({ node, message });
},
CallExpression(node) {
const calleeName = getNodeName(node.callee);
if (
calleeName === 'require' &&
node.arguments[0] &&
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,
});
}
'CallExpression[callee.name="require"][arguments.0.value="jest"]'(node) {
context.report({
loc: node.arguments[0].loc,
message,
});
},
};
},
Expand Down

0 comments on commit 2a1ae17

Please # to comment.