import-js/eslint-plugin-import

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

開放

#2,725 建立於 2023年2月23日

 (1 則留言) (0 個反應) (0 位負責人)JavaScript (1,548 個分叉)batch import
help wantedtypescript

倉庫指標

星標
 (5,940 顆星)
PR 合併指標
 (PR 指標待抓取)

描述

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch eslint-plugin-import@2.27.5 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.

貢獻者指南