2024-06-11 20:32:02 +08:00
|
|
|
const js = require("@eslint/js");
|
|
|
|
const prettier = require("eslint-plugin-prettier");
|
|
|
|
const n = require("eslint-plugin-n");
|
|
|
|
const jest = require("eslint-plugin-jest");
|
|
|
|
const jsdoc = require("eslint-plugin-jsdoc");
|
|
|
|
const prettierConfig = require("eslint-config-prettier");
|
|
|
|
const globals = require("globals");
|
|
|
|
|
2024-07-31 09:37:24 +08:00
|
|
|
const nodeConfig = n.configs["flat/recommended"];
|
2024-07-30 21:48:58 +08:00
|
|
|
const jsdocConfig = jsdoc.configs["flat/recommended-typescript-flavor-error"];
|
|
|
|
|
2024-06-11 20:32:02 +08:00
|
|
|
module.exports = [
|
|
|
|
{
|
|
|
|
ignores: [
|
|
|
|
// Ignore some test files
|
|
|
|
"test/**/*.*",
|
|
|
|
"!test/*.js",
|
|
|
|
"!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/helpers/*.*",
|
|
|
|
|
|
|
|
// Ignore some folders
|
|
|
|
"benchmark",
|
|
|
|
"coverage",
|
|
|
|
|
|
|
|
// Ignore generated files
|
|
|
|
"*.check.js",
|
|
|
|
|
|
|
|
// Ignore not supported files
|
|
|
|
"*.d.ts",
|
|
|
|
|
|
|
|
// Ignore precompiled schemas
|
|
|
|
"schemas/**/*.check.js",
|
|
|
|
|
2024-07-31 09:37:24 +08:00
|
|
|
// Auto generation
|
|
|
|
"lib/util/semver.js",
|
|
|
|
|
2024-06-11 20:32:02 +08:00
|
|
|
// Ignore some examples files
|
|
|
|
"examples/**/*.js",
|
|
|
|
"examples/**/*.mjs",
|
|
|
|
"!examples/*/webpack.config.js"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
js.configs.recommended,
|
2024-07-31 09:37:24 +08:00
|
|
|
{
|
|
|
|
...nodeConfig,
|
|
|
|
rules: {
|
|
|
|
...nodeConfig.rules,
|
|
|
|
"n/no-missing-require": ["error", { allowModules: ["webpack"] }],
|
|
|
|
"n/no-unsupported-features/node-builtins": [
|
|
|
|
"error",
|
|
|
|
{
|
|
|
|
ignores: ["zlib.createBrotliCompress", "zlib.createBrotliDecompress"]
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"n/exports-style": "error"
|
|
|
|
}
|
|
|
|
},
|
2024-07-30 21:48:58 +08:00
|
|
|
{
|
|
|
|
...jsdocConfig,
|
2024-07-31 09:37:24 +08:00
|
|
|
settings: {
|
|
|
|
jsdoc: {
|
|
|
|
mode: "typescript",
|
|
|
|
// supported tags https://github.com/microsoft/TypeScript-wiki/blob/master/JSDoc-support-in-JavaScript.md
|
|
|
|
tagNamePreference: {
|
|
|
|
...["implements", "const", "memberof", "yields"].reduce(
|
|
|
|
(acc, tag) => {
|
|
|
|
acc[tag] = {
|
|
|
|
message: `@${tag} currently not supported in TypeScript`
|
|
|
|
};
|
|
|
|
return acc;
|
|
|
|
},
|
|
|
|
{}
|
|
|
|
),
|
|
|
|
extends: "extends",
|
|
|
|
return: "returns",
|
|
|
|
constructor: "constructor",
|
|
|
|
prop: "property",
|
|
|
|
arg: "param",
|
|
|
|
augments: "extends",
|
|
|
|
description: false,
|
|
|
|
desc: false,
|
|
|
|
inheritdoc: false,
|
|
|
|
class: "constructor"
|
|
|
|
},
|
|
|
|
overrideReplacesDocs: false
|
|
|
|
}
|
|
|
|
},
|
2024-07-30 21:48:58 +08:00
|
|
|
rules: {
|
|
|
|
...jsdocConfig.rules,
|
|
|
|
// Override recommended
|
|
|
|
// TODO remove me after switch to typescript strict mode
|
|
|
|
"jsdoc/require-jsdoc": "off",
|
|
|
|
// Doesn't support function overloading/tuples/`readonly`/module keyword/etc
|
|
|
|
// Also `typescript` reports this itself
|
|
|
|
"jsdoc/valid-types": "off",
|
|
|
|
// A lot of false positive with loops/`switch`/`if`/etc
|
|
|
|
"jsdoc/require-returns-check": "off",
|
|
|
|
// TODO fix and enable in future
|
|
|
|
"jsdoc/require-property-description": "off",
|
|
|
|
|
|
|
|
// More rules
|
|
|
|
"jsdoc/check-indentation": "error",
|
|
|
|
"jsdoc/no-bad-blocks": "error",
|
|
|
|
"jsdoc/require-hyphen-before-param-description": ["error", "never"],
|
|
|
|
"jsdoc/require-template": "error",
|
|
|
|
"jsdoc/no-blank-block-descriptions": "error",
|
|
|
|
"jsdoc/no-blank-blocks": "error",
|
|
|
|
"jsdoc/require-asterisk-prefix": "error"
|
|
|
|
}
|
|
|
|
},
|
2024-06-11 20:32:02 +08:00
|
|
|
prettierConfig,
|
|
|
|
{
|
|
|
|
languageOptions: {
|
|
|
|
ecmaVersion: 2018,
|
|
|
|
globals: {
|
|
|
|
...globals.node,
|
2024-07-31 04:09:42 +08:00
|
|
|
...globals.es2018,
|
2024-06-11 20:32:02 +08:00
|
|
|
WebAssembly: true
|
|
|
|
}
|
|
|
|
},
|
|
|
|
linterOptions: {
|
|
|
|
reportUnusedDisableDirectives: true
|
|
|
|
},
|
|
|
|
plugins: {
|
|
|
|
prettier
|
|
|
|
},
|
|
|
|
rules: {
|
|
|
|
"prettier/prettier": "error",
|
|
|
|
"no-template-curly-in-string": "error",
|
|
|
|
"no-caller": "error",
|
|
|
|
"no-control-regex": "off",
|
|
|
|
yoda: "error",
|
|
|
|
eqeqeq: "error",
|
|
|
|
"eol-last": "error",
|
|
|
|
"no-extra-bind": "warn",
|
|
|
|
"no-process-exit": "warn",
|
|
|
|
"no-use-before-define": "off",
|
|
|
|
"no-unused-vars": [
|
|
|
|
"error",
|
2024-07-31 09:37:24 +08:00
|
|
|
{
|
|
|
|
vars: "all",
|
|
|
|
varsIgnorePattern: "^_",
|
|
|
|
args: "none",
|
|
|
|
argsIgnorePattern: "^_",
|
|
|
|
caughtErrors: "none",
|
|
|
|
caughtErrorsIgnorePattern: "^_",
|
|
|
|
ignoreRestSiblings: true
|
|
|
|
}
|
2024-06-11 20:32:02 +08:00
|
|
|
],
|
|
|
|
"no-inner-declarations": "error",
|
2024-07-31 04:09:42 +08:00
|
|
|
"prefer-const": [
|
|
|
|
"error",
|
|
|
|
{
|
|
|
|
destructuring: "all",
|
|
|
|
ignoreReadBeforeAssign: true
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"object-shorthand": "error",
|
2024-07-31 04:21:27 +08:00
|
|
|
"no-else-return": "error",
|
2024-07-31 04:54:55 +08:00
|
|
|
"no-lonely-if": "error",
|
2024-07-31 06:15:03 +08:00
|
|
|
"no-undef-init": "error",
|
2024-07-31 09:37:24 +08:00
|
|
|
// Disallow @ts-ignore directive. Use @ts-expect-error instead
|
|
|
|
"no-warning-comments": [
|
|
|
|
"error",
|
|
|
|
{ terms: ["@ts-ignore"], location: "start" }
|
|
|
|
],
|
|
|
|
"no-constructor-return": "error",
|
|
|
|
"symbol-description": "error",
|
|
|
|
"array-callback-return": [
|
2024-06-11 21:26:12 +08:00
|
|
|
"error",
|
|
|
|
{
|
2024-07-31 09:37:24 +08:00
|
|
|
allowImplicit: true
|
2024-06-11 21:26:12 +08:00
|
|
|
}
|
|
|
|
],
|
2024-07-31 09:37:24 +08:00
|
|
|
"no-promise-executor-return": "error",
|
|
|
|
"no-undef": "error",
|
|
|
|
"guard-for-in": "error",
|
|
|
|
"no-constant-condition": "error",
|
|
|
|
camelcase: [
|
2024-06-11 20:32:02 +08:00
|
|
|
"error",
|
2024-07-31 09:37:24 +08:00
|
|
|
{
|
|
|
|
allow: [
|
|
|
|
"__webpack_require__",
|
|
|
|
"__webpack_public_path__",
|
|
|
|
"__webpack_base_uri__",
|
|
|
|
"__webpack_modules__",
|
|
|
|
"__webpack_chunk_load__",
|
|
|
|
"__non_webpack_require__",
|
|
|
|
"__webpack_nonce__",
|
|
|
|
"__webpack_hash__",
|
|
|
|
"__webpack_chunkname__",
|
|
|
|
"__webpack_get_script_filename__",
|
|
|
|
"__webpack_runtime_id__",
|
|
|
|
"__system_context__",
|
|
|
|
"__webpack_share_scopes__",
|
|
|
|
"__webpack_init_sharing__",
|
|
|
|
"__webpack_require_module__",
|
|
|
|
"_stream_duplex",
|
|
|
|
"_stream_passthrough",
|
|
|
|
"_stream_readable",
|
|
|
|
"_stream_transform",
|
|
|
|
"_stream_writable",
|
|
|
|
"string_decoder"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"prefer-exponentiation-operator": "error",
|
|
|
|
"no-useless-return": "error",
|
|
|
|
"no-return-assign": "error",
|
|
|
|
"default-case-last": "error",
|
|
|
|
"default-param-last": "error",
|
|
|
|
"dot-notation": "error",
|
|
|
|
"grouped-accessor-pairs": "error",
|
|
|
|
"id-match": [
|
|
|
|
"error",
|
|
|
|
"^[$a-zA-Z_][$a-zA-Z0-9_]*$",
|
|
|
|
{
|
|
|
|
properties: true
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"no-extra-label": "error",
|
|
|
|
"no-label-var": "error",
|
|
|
|
"no-lone-blocks": "error",
|
|
|
|
"no-multi-str": "error",
|
|
|
|
"no-new-func": "error",
|
|
|
|
"no-unneeded-ternary": ["error", { defaultAssignment: false }],
|
|
|
|
"no-useless-call": "error",
|
|
|
|
"no-useless-concat": "error",
|
|
|
|
"prefer-object-spread": "error",
|
|
|
|
"prefer-regex-literals": "error",
|
|
|
|
"prefer-rest-params": "error",
|
|
|
|
|
|
|
|
// TODO Enable
|
|
|
|
"no-sequences": "off",
|
|
|
|
"prefer-spread": "off",
|
|
|
|
"default-case": "off",
|
|
|
|
"new-cap": [
|
|
|
|
"off",
|
|
|
|
{
|
|
|
|
newIsCap: true,
|
|
|
|
newIsCapExceptions: [],
|
|
|
|
capIsNew: true,
|
|
|
|
capIsNewExceptions: [],
|
|
|
|
properties: true
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"no-loop-func": "off",
|
|
|
|
"no-implicit-coercion": "off",
|
|
|
|
"arrow-body-style": "off",
|
|
|
|
"no-shadow": "off",
|
|
|
|
"prefer-template": "off",
|
|
|
|
"prefer-destructuring": "off",
|
|
|
|
"func-style": "off",
|
|
|
|
"no-plusplus": "off",
|
|
|
|
"no-param-reassign": "off",
|
|
|
|
"no-var": "off",
|
|
|
|
"one-var": "off",
|
|
|
|
"vars-on-top": "off",
|
|
|
|
"no-unreachable-loop": "off",
|
|
|
|
"no-unmodified-loop-condition": "off",
|
|
|
|
"@stylistic/lines-between-class-members": "off",
|
|
|
|
"@stylistic/quotes": "off",
|
|
|
|
"@stylistic/spaced-comment": "off",
|
|
|
|
// TODO Disable everywhere?
|
|
|
|
"no-useless-constructor": "off"
|
2024-06-11 20:32:02 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
files: ["bin/**/*.js"],
|
|
|
|
// Allow to use `dynamic` import
|
|
|
|
languageOptions: {
|
|
|
|
ecmaVersion: 2020
|
|
|
|
},
|
|
|
|
rules: {
|
|
|
|
"n/no-unsupported-features/es-syntax": [
|
|
|
|
"error",
|
|
|
|
{
|
|
|
|
ignores: ["hashbang", "dynamic-import"]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
files: ["lib/**/*.runtime.js", "hot/*.js"],
|
|
|
|
languageOptions: {
|
|
|
|
ecmaVersion: 5,
|
|
|
|
globals: {
|
|
|
|
...globals.browser,
|
|
|
|
...globals.es5
|
|
|
|
}
|
2024-07-31 04:09:42 +08:00
|
|
|
},
|
|
|
|
rules: {
|
|
|
|
"prefer-const": "off",
|
2024-07-31 04:54:55 +08:00
|
|
|
"object-shorthand": "off",
|
2024-07-31 06:15:03 +08:00
|
|
|
"no-undef-init": "off",
|
2024-07-31 04:54:55 +08:00
|
|
|
"n/exports-style": "off"
|
2024-06-11 20:32:02 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
files: ["tooling/**/*.js"],
|
|
|
|
languageOptions: {
|
|
|
|
ecmaVersion: 2020,
|
|
|
|
globals: {
|
2024-07-31 04:09:42 +08:00
|
|
|
...globals.es2020
|
2024-06-11 20:32:02 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
...jest.configs["flat/recommended"],
|
|
|
|
files: ["test/**/*.js"],
|
|
|
|
languageOptions: {
|
|
|
|
ecmaVersion: 2020,
|
|
|
|
globals: {
|
|
|
|
...globals.jest,
|
|
|
|
nsObj: false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
rules: {
|
|
|
|
...jest.configs["flat/recommended"].rules,
|
|
|
|
"jest/no-standalone-expect": "off",
|
|
|
|
"jest/valid-title": [
|
|
|
|
"error",
|
|
|
|
{
|
|
|
|
ignoreTypeOfDescribeName: true,
|
|
|
|
ignoreTypeOfTestName: true
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"jest/no-done-callback": "off",
|
|
|
|
"jest/expect-expect": "off",
|
|
|
|
"jest/no-conditional-expect": "off",
|
|
|
|
"n/no-unsupported-features/node-builtins": [
|
|
|
|
"error",
|
|
|
|
{
|
|
|
|
allowExperimental: true
|
|
|
|
}
|
2024-07-31 04:09:42 +08:00
|
|
|
],
|
2024-07-31 09:37:24 +08:00
|
|
|
"object-shorthand": "off",
|
|
|
|
camelcase: "off"
|
2024-06-11 20:32:02 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
files: ["examples/**/*.js"],
|
|
|
|
rules: {
|
|
|
|
"n/no-missing-require": "off"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
];
|