import-js/eslint-plugin-import
Voir sur GitHubusing 'import type' and module.exports in the same file should not raise an error for no-import-module-exports
Open
#2 725 ouverte le 23 févr. 2023
help wantedtypescript
Métriques du dépôt
- Stars
- (4 946 stars)
- Métriques de merge PR
- (Merge moyen 138j 22h) (3 PRs mergées en 30 j)
Description
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.