Skip to content

Commit 8a80cb7

Browse files
[Fix]: no-import-module-exports false positive for import variables
1 parent e156316 commit 8a80cb7

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/rules/no-import-module-exports.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ function findScope(context, identifier) {
1919
return scopeManager && scopeManager.scopes.slice().reverse().find((scope) => scope.variables.some(variable => variable.identifiers.some((node) => node.name === identifier)));
2020
}
2121

22+
function findDefinition(objectScope, identifier) {
23+
const variable = objectScope.variables.find(variable => variable.name === identifier);
24+
return variable.defs.find(def => def.name.name === identifier);
25+
}
26+
2227
module.exports = {
2328
meta: {
2429
type: 'problem',
@@ -50,10 +55,12 @@ module.exports = {
5055
const isIdentifier = node.object.type === 'Identifier';
5156
const hasKeywords = (/^(module|exports)$/).test(node.object.name);
5257
const objectScope = hasKeywords && findScope(context, node.object.name);
58+
const variableDefinition = objectScope && findDefinition(objectScope, node.object.name);
59+
const isImportBinding = variableDefinition && variableDefinition.type === 'ImportBinding';
5360
const hasCJSExportReference = hasKeywords && (!objectScope || objectScope.type === 'module');
5461
const isException = !!options.exceptions && options.exceptions.some(glob => minimatch(fileName, glob));
5562

56-
if (isIdentifier && hasCJSExportReference && !isEntryPoint && !isException) {
63+
if (isIdentifier && hasCJSExportReference && !isEntryPoint && !isException && !isImportBinding) {
5764
importDeclarations.forEach(importDeclaration => {
5865
context.report({
5966
node: importDeclaration,

tests/src/rules/no-import-module-exports.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ ruleTester.run('no-import-module-exports', rule, {
4040
exports.foo = bar
4141
`,
4242
}),
43+
test({
44+
code: `
45+
import { module } from 'qunit'
46+
module.skip('A test', function () {})
47+
`,
48+
}),
4349
test({
4450
code: `
4551
import foo from 'path';

0 commit comments

Comments
 (0)