eslint-plugin-import icon indicating copy to clipboard operation
eslint-plugin-import copied to clipboard

using 'import type' and module.exports in the same file should not raise an error for no-import-module-exports

Open lior-frezi opened this issue 2 years ago • 1 comments

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch [email protected] for the project I'm working on.

in typescript 'import type' gets dropped in the build, so it is safe to use 'import type' with 'module.exports' (it is the only valid way to import types in a file with modules.exports).

Here is the diff that solved my problem:

diff --git a/node_modules/eslint-plugin-import/lib/rules/no-import-module-exports.js b/node_modules/eslint-plugin-import/lib/rules/no-import-module-exports.js
index b93d96e..d14049f 100644
--- a/node_modules/eslint-plugin-import/lib/rules/no-import-module-exports.js
+++ b/node_modules/eslint-plugin-import/lib/rules/no-import-module-exports.js
@@ -64,9 +64,7 @@ module.exports = {
           importDeclarations.forEach(function (importDeclaration) {
             context.report({
               node: importDeclaration,
-              message: 'Cannot use import declarations in modules that export using ' + 'CommonJS (module.exports = \'foo\' or exports.bar = \'hi\')' });
-
-
+              message: 'Cannot use import declarations (that are not top level type imports) in modules that export using ' + 'CommonJS (module.exports = \'foo\' or exports.bar = \'hi\')' });
           });
           alreadyReported = true;
         }
@@ -74,7 +72,9 @@ module.exports = {
 
       return {
         ImportDeclaration: function () {function ImportDeclaration(node) {
+          if(node.importKind !== 'type'){
             importDeclarations.push(node);
+          }
           }return ImportDeclaration;}(),
         MemberExpression: function () {function MemberExpression(node) {
             if (!alreadyReported) {

This issue body was partially generated by patch-package.

lior-frezi avatar Feb 23 '23 10:02 lior-frezi

If you can provide test cases, that seems like a good PR to open :-)

ljharb avatar Feb 23 '23 17:02 ljharb