webpack/eslint.config.mjs

232 lines
5.0 KiB
JavaScript
Raw Normal View History

2025-04-22 05:17:46 +08:00
import { defineConfig, globalIgnores } from "eslint/config";
import config from "eslint-config-webpack";
import configs from "eslint-config-webpack/configs.js";
2025-03-07 23:32:55 +08:00
import globals from "globals";
2024-07-30 21:48:58 +08:00
2025-04-22 05:17:46 +08:00
export default defineConfig([
globalIgnores([
// Ignore some test files
"test/**/*.*",
"!test/*.js",
"!test/*.cjs",
"!test/*.mjs",
"!test/**/webpack.config.js",
"!test/**/test.config.js",
"!test/**/test.filter.js",
"test/cases/parsing/es2022/test.filter.js",
"!test/**/errors.js",
"!test/**/warnings.js",
"!test/**/deprecations.js",
"!test/**/infrastructure-log.js",
"!test/helpers/*.*",
"!test/benchmarkCases/**/*.mjs",
"!test/_helpers/**/*.mjs",
2025-04-22 05:17:46 +08:00
"test/js/**/*.*",
2024-06-11 20:32:02 +08:00
// TODO fix me
// This is not exactly typescript
"assembly/**/*.ts",
2025-04-22 05:17:46 +08:00
// Ignore some folders
"benchmark",
"coverage",
2024-06-11 20:32:02 +08:00
2025-04-22 05:17:46 +08:00
// Ignore generated files
"*.check.js",
2024-06-11 20:32:02 +08:00
2025-04-22 05:17:46 +08:00
// Ignore not supported files
"*.d.ts",
2024-06-11 20:32:02 +08:00
2025-04-22 05:17:46 +08:00
// Ignore precompiled schemas
"schemas/**/*.check.js",
2024-06-11 20:32:02 +08:00
2025-04-22 05:17:46 +08:00
// Auto generation
"lib/util/semver.js",
2024-07-31 09:37:24 +08:00
2025-04-22 05:17:46 +08:00
// Ignore some examples files
"examples/**/*.{js,cjs,mjs,jsx,ts,cts,mts,tsx,md}",
2025-04-22 05:17:46 +08:00
"!examples/*/webpack.config.js"
]),
{
ignores: ["lib/**/*.runtime.js", "hot/*.js"],
extends: [config],
2025-04-22 05:17:46 +08:00
rules: {
// Revisit it in future
"id-length": "off",
// Revisit it in future
"no-use-before-define": "off",
// We have helpers for the default configuration
"new-cap": [
2025-04-22 05:17:46 +08:00
"error",
{
newIsCapExceptions: [],
capIsNewExceptions: ["A", "F", "D", "MODULES_GROUPERS"]
2025-04-22 05:17:46 +08:00
}
],
// TODO enable me in future
"prefer-destructuring": "off",
// TODO enable me in future, we need to ignore Object.define
"func-names": "off",
// TODO enable me in future
"unicorn/prefer-spread": "off",
// TODO need patch in tooling, now we are doing weird order for destructuring in cjs import
"import/order": "off",
// TODO We need allow to have `_arg` in tooling and use `after-used` value for `args`
2024-06-11 20:32:02 +08:00
"no-unused-vars": [
"error",
2024-07-31 09:37:24 +08:00
{
vars: "all",
varsIgnorePattern: "^_",
args: "none",
argsIgnorePattern: "^_",
2024-07-31 15:37:05 +08:00
caughtErrors: "all",
2024-07-31 09:37:24 +08:00
caughtErrorsIgnorePattern: "^_",
destructuredArrayIgnorePattern: "^_",
ignoreRestSiblings: true,
ignoreClassWithStaticInitBlock: false,
reportUsedIgnorePattern: false
2024-07-31 09:37:24 +08:00
}
],
// Too noise
"jsdoc/require-property-description": "off",
// TODO enable me in future
"unicorn/prefer-regexp-test": "off",
"unicorn/prefer-string-slice": "off",
// TODO false positive, need to fix in upstream
"n/prefer-node-protocol": "off",
"n/prefer-global/url": "off"
2024-07-31 12:23:44 +08:00
}
},
2024-07-31 15:37:05 +08:00
{
files: ["lib/**/*.js"],
extends: [configs["webpack/special"]]
2024-07-31 15:37:05 +08:00
},
2024-07-31 12:23:44 +08:00
{
files: ["bin/**/*.js"],
// Allow to use `dynamic` import
languageOptions: {
ecmaVersion: 2020
2024-07-31 12:23:44 +08:00
},
rules: {
"no-console": "off",
// Allow to use `dynamic` import and hashbang
"n/no-unsupported-features/es-syntax": [
2024-07-31 12:23:44 +08:00
"error",
{
ignores: ["hashbang", "dynamic-import"]
2024-07-31 12:23:44 +08:00
}
]
2024-06-11 20:32:02 +08:00
}
},
2024-07-31 12:01:14 +08:00
{
files: ["lib/**/*.runtime.js", "hot/*.js"],
extends: [configs["javascript/es5"]],
languageOptions: {
sourceType: "commonjs",
globals: {
...globals.browser,
...globals.es5,
Promise: false,
Map: false,
Set: false,
process: false
2024-07-31 12:01:14 +08:00
}
},
rules: {
strict: "off",
2024-07-31 12:01:14 +08:00
"block-scoped-var": "off",
// Allow logging
"no-console": "off",
// We replace `$VAR$` on real code
"no-unused-vars": "off",
"no-undef-init": "off",
"id-length": "off",
"unicorn/no-array-for-each": "off",
"unicorn/prefer-includes": "off",
"jsdoc/require-jsdoc": "off",
// Revisit it in future
"no-use-before-define": "off",
"func-names": "off",
"func-style": "off"
2024-07-31 12:01:14 +08:00
}
},
2024-06-11 20:32:02 +08:00
{
files: ["test/**/*.js"],
2024-06-11 20:32:02 +08:00
rules: {
// TODO enable me
strict: "off",
// No need here, we have custom test logic, so except can be placed in different places
2025-04-22 05:17:46 +08:00
"jest/no-standalone-expect": "off",
// We have a lot of custom tests
2025-04-22 05:17:46 +08:00
"jest/expect-expect": "off",
// We have a lot of custom tests
"jest/no-confusing-set-timeout": "off"
2024-06-11 20:32:02 +08:00
}
},
{
files: ["test/helpers/**/*.{js,cjs,mjs}"],
2024-06-11 20:32:02 +08:00
languageOptions: {
globals: {
...globals.jest
2024-06-11 20:32:02 +08:00
}
2024-07-31 04:09:42 +08:00
},
rules: {
"no-eval": "off",
2025-04-22 05:17:46 +08:00
"no-console": "off",
// Allow to use any builtins, syntax and node API in tests
"n/no-unsupported-features/es-builtins": "off",
"n/no-unsupported-features/es-syntax": "off",
"n/no-unsupported-features/node-builtins": "off"
2024-06-11 20:32:02 +08:00
}
},
{
files: ["test/**/*.mjs"],
2024-06-11 20:32:02 +08:00
languageOptions: {
ecmaVersion: 2022
2024-06-11 20:32:02 +08:00
}
},
2024-08-02 23:42:44 +08:00
{
2025-04-22 05:17:46 +08:00
files: ["setup/**/*.js", "tooling/**/*.js"],
languageOptions: {
ecmaVersion: 2022
2025-04-22 05:17:46 +08:00
},
2025-03-07 23:32:55 +08:00
rules: {
2025-04-22 05:17:46 +08:00
"no-console": "off"
2025-03-07 23:32:55 +08:00
}
},
{
files: ["test/Compiler-filesystem-caching.test.js"],
languageOptions: {
ecmaVersion: 2022
}
},
2024-06-11 20:32:02 +08:00
{
2025-04-22 05:17:46 +08:00
files: [
"test/configCases/{dll-plugin-entry,dll-plugin-side-effects,dll-plugin}/**/webpack.config.js",
"examples/**/*.js",
"test/NodeTemplatePlugin.test.js",
"test/PersistentCaching.test.js"
2025-04-22 05:17:46 +08:00
],
2024-06-11 20:32:02 +08:00
rules: {
"import/extensions": "off",
"import/no-unresolved": "off"
2024-07-31 12:01:14 +08:00
}
2024-06-11 20:32:02 +08:00
}
2025-04-22 05:17:46 +08:00
]);