From 2686f0b2a78795eb699151e5d6bf085be3a33da3 Mon Sep 17 00:00:00 2001 From: zanminkian Date: Mon, 18 Sep 2023 16:24:54 +0000 Subject: [PATCH] feat(eslint-config): ban commonjs in js file --- .changeset/proud-cheetahs-deny.md | 5 +++++ packages/eslint-config/src/js-config/index.js | 10 ++++++---- packages/eslint-config/src/ts-config.js | 4 ---- 3 files changed, 11 insertions(+), 8 deletions(-) create mode 100644 .changeset/proud-cheetahs-deny.md diff --git a/.changeset/proud-cheetahs-deny.md b/.changeset/proud-cheetahs-deny.md new file mode 100644 index 00000000..5ccf2d39 --- /dev/null +++ b/.changeset/proud-cheetahs-deny.md @@ -0,0 +1,5 @@ +--- +"@git-validator/eslint-config": patch +--- + +feat(eslint-config): ban commonjs in js file diff --git a/packages/eslint-config/src/js-config/index.js b/packages/eslint-config/src/js-config/index.js index 2b97d6b0..ca256fef 100644 --- a/packages/eslint-config/src/js-config/index.js +++ b/packages/eslint-config/src/js-config/index.js @@ -14,9 +14,7 @@ export default { // override standard config rules "comma-dangle": ["error", "always-multiline"], "brace-style": ["error", "1tbs", { allowSingleLine: false }], // https://github.com/standard/eslint-config-standard/pull/281 - // `const fun = (foo: never) => foo['bar']` will be formatted to `const fun = (foo: never) => foo.bar`. - // it's incorrect when enabling ts-check. so turn it off. - "dot-notation": "off", + "dot-notation": "off", // conflict when enabling ts-check so turn it off // code style for a better readability "max-statements-per-line": ["error", { max: 1 }], @@ -32,8 +30,12 @@ export default { "arrow-body-style": ["error", "as-needed"], // ban some syntaxes to reduce mistakes + "import/no-commonjs": [ + "error", + { allowRequire: false, allowConditionalRequire: false, allowPrimitiveModules: false }, + ], "import/no-self-import": "error", - "import/no-dynamic-require": "error", // TODO remove it once we have ban commonjs in js file. + "import/no-dynamic-require": "error", "import/no-relative-packages": "error", "import/no-mutable-exports": "error", // forbid code like `export let count = 3` // "import/no-named-as-default-member": "error", // forbid code like `import foo from './foo.js'; const bar = foo.bar;` diff --git a/packages/eslint-config/src/ts-config.js b/packages/eslint-config/src/ts-config.js index 6e8a9172..4ec48186 100644 --- a/packages/eslint-config/src/ts-config.js +++ b/packages/eslint-config/src/ts-config.js @@ -105,10 +105,6 @@ export default { "no-void": ["error", { allowAsStatement: true }], // ban some syntaxes to reduce mistakes - "import/no-commonjs": [ - "error", - { allowRequire: false, allowConditionalRequire: false, allowPrimitiveModules: false }, - ], // TODO move this rule to base. js file should not use commonjs too. "@typescript-eslint/ban-types": "error", "@typescript-eslint/method-signature-style": "error", "@typescript-eslint/no-require-imports": "error",