Skip to content

Commit 2a6f441

Browse files
committed
fix: Refine eslint import plugin rules to accommodate .jsx and .cjs
This change adds ".jsx" and ".cjs" to the list of recognized file extensions in the eslint import resolver. This allows better support and error handling for these newly accepted file types. Furthermore, the rule "import/no-commonjs" has been fine-tuned to allow primitive modules, but discourage non-primitive 'require' statements, providing a clearer distinction between anti-patterns and necessary exceptions. "import/no-unused-modules" rule has been edited to prevent it from considering ".cjs" files as unused modules. Signed-off-by: prisis <[email protected]>
1 parent 0ea963f commit 2a6f441

File tree

1 file changed

+3
-3
lines changed
  • packages/eslint-config/src/config/plugins

1 file changed

+3
-3
lines changed

packages/eslint-config/src/config/plugins/import.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ const config: Linter.Config = createConfigs([
117117

118118
// disallow require()
119119
// https://github.com/import-js/eslint-plugin-import/blob/main/docs/rules/no-commonjs.md
120-
"import/no-commonjs": packageIsTypeModule ? "error" : "off",
120+
"import/no-commonjs": packageIsTypeModule ? ["error", { allowPrimitiveModules: true }] : "off",
121121

122122
// Forbid cyclical dependencies between modules
123123
// https://medium.com/@steven-lemon182/are-typescript-barrel-files-an-anti-pattern-72a713004250
@@ -254,7 +254,7 @@ const config: Linter.Config = createConfigs([
254254
"import/no-unused-modules": [
255255
packageIsTypeModule ? "error" : "off",
256256
{
257-
ignoreExports: [],
257+
ignoreExports: ["**/*.cjs"],
258258
missingExports: true,
259259
unusedExports: true,
260260
},
@@ -305,7 +305,7 @@ const config: Linter.Config = createConfigs([
305305
"import/ignore": ["\\.(coffee|scss|css|less|hbs|svg|json)$"],
306306
"import/resolver": {
307307
node: {
308-
extensions: [".mjs", ".js", ".json"],
308+
extensions: [".mjs", ".js", ".json", ".cjs", ".jsx"],
309309
},
310310
...(hasTypescript
311311
? {

0 commit comments

Comments
 (0)