@pob/eslint-config 67.13.0 → 68.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/_base.js +21 -31
- package/lib/eslint-rules.test.js +1 -3
- package/lib/index.js +77 -343
- package/lib/index.test.js +76 -40
- package/lib/node.js +60 -0
- package/lib/overrides/dev-only.js +10 -0
- package/lib/overrides/scripts.js +1 -1
- package/lib/overrides/test.js +7 -45
- package/lib/overrides/tools-project.js +4 -10
- package/lib/oxlint-js-plugins-rules.test.js +62 -0
- package/lib/oxlint-rules.test.js +2 -4
- package/lib/oxlint.test.js +58 -46
- package/lib/plugins/import.js +69 -0
- package/lib/typescript.js +27 -0
- package/oxlint/base.json +6 -0
- package/oxlint/commonjs.json +17 -0
- package/package.json +6 -13
- package/lib/base/commonjs.js +0 -15
- package/lib/base/module.js +0 -29
- package/lib/node/_base.js +0 -35
- package/lib/node/commonjs.js +0 -25
- package/lib/node/module.js +0 -35
- package/lib/node/typescript.js +0 -15
- package/lib/overrides/allow-implicit-return-type.js +0 -7
- package/lib/overrides/allow-unsafe-as-warn.js +0 -10
- package/lib/overrides/allow-unsafe.js +0 -10
- package/lib/overrides/app.js +0 -8
- package/lib/plugins/import/import-base.js +0 -136
- package/lib/plugins/import/import-commonjs.js +0 -7
- package/lib/plugins/import/import-module.js +0 -7
- package/lib/plugins/node.js +0 -17
- package/lib/plugins/regexp.js +0 -12
- package/lib/plugins/typescript-eslint/typescript-eslint-replace-eslint.js +0 -126
- package/lib/plugins/typescript-eslint/typescript-eslint-replace-unicorn.js +0 -13
- package/lib/plugins/typescript-eslint/typescript-eslint-rules.js +0 -216
- package/lib/plugins/unicorn.js +0 -392
- package/lib/rules/best-practices.js +0 -506
- package/lib/rules/code-quality.js +0 -10
- package/lib/rules/dev-only.js +0 -15
- package/lib/rules/errors.js +0 -128
- package/lib/rules/node.js +0 -26
- package/lib/rules/style.js +0 -34
- package/lib/rules/typescript.js +0 -61
- package/lib/utils/oxlint.js +0 -136
- package/lib/utils/oxlint.test.js +0 -197
package/lib/rules/style.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
name: "@pob/eslint-config/style",
|
|
3
|
-
rules: {
|
|
4
|
-
// changed properties: 'never' to properties: 'always' ; true to 'ignoreDestructuring': false
|
|
5
|
-
// http://eslint.org/docs/rules/camelcase
|
|
6
|
-
camelcase: ["error", { properties: "always", ignoreDestructuring: false }],
|
|
7
|
-
|
|
8
|
-
// http://eslint.org/docs/rules/object-shorthand
|
|
9
|
-
"object-shorthand": ["error", "always"],
|
|
10
|
-
|
|
11
|
-
// https://github.com/prettier/eslint-config-prettier#curly
|
|
12
|
-
// prettier doesn't enforce {} with multiline
|
|
13
|
-
curly: ["warn", "multi-line"],
|
|
14
|
-
|
|
15
|
-
// https://github.com/prettier/eslint-config-prettier#quotes
|
|
16
|
-
// prettier doesn't change backtick to single
|
|
17
|
-
quotes: [
|
|
18
|
-
"warn",
|
|
19
|
-
"double",
|
|
20
|
-
{ avoidEscape: true, allowTemplateLiterals: false },
|
|
21
|
-
],
|
|
22
|
-
|
|
23
|
-
// https://eslint.org/docs/latest/rules/sort-imports ; declaration is sorted using import/order
|
|
24
|
-
"sort-imports": ["error", { ignoreDeclarationSort: true }],
|
|
25
|
-
|
|
26
|
-
/* disabled rules */
|
|
27
|
-
|
|
28
|
-
// http://eslint.org/docs/rules/no-else-return
|
|
29
|
-
"no-else-return": "off",
|
|
30
|
-
|
|
31
|
-
// http://eslint.org/docs/rules/arrow-body-style
|
|
32
|
-
"arrow-body-style": "off",
|
|
33
|
-
},
|
|
34
|
-
};
|
package/lib/rules/typescript.js
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import { createNodeResolver } from "eslint-plugin-import-x";
|
|
2
|
-
|
|
3
|
-
export default {
|
|
4
|
-
name: "@pob/eslint-config/typescript",
|
|
5
|
-
languageOptions: {
|
|
6
|
-
parserOptions: {
|
|
7
|
-
project: true,
|
|
8
|
-
},
|
|
9
|
-
},
|
|
10
|
-
settings: {
|
|
11
|
-
"import-x/resolver-next": [
|
|
12
|
-
createNodeResolver({
|
|
13
|
-
extensions: [".mjs", ".js", ".json", ".ts"],
|
|
14
|
-
conditionNames: ["import"],
|
|
15
|
-
}),
|
|
16
|
-
],
|
|
17
|
-
"import-x/extensions": [".js", ".mjs", ".ts", ".d.ts"],
|
|
18
|
-
},
|
|
19
|
-
rules: {
|
|
20
|
-
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/import/no-anonymous-default-export.md
|
|
21
|
-
// Reports if a module's default export is unnamed
|
|
22
|
-
"import-x/no-anonymous-default-export": [
|
|
23
|
-
"error",
|
|
24
|
-
{
|
|
25
|
-
allowArray: true,
|
|
26
|
-
allowArrowFunction: false,
|
|
27
|
-
allowAnonymousClass: false,
|
|
28
|
-
allowAnonymousFunction: false,
|
|
29
|
-
allowCallExpression: true,
|
|
30
|
-
allowLiteral: true,
|
|
31
|
-
allowObject: true,
|
|
32
|
-
},
|
|
33
|
-
],
|
|
34
|
-
|
|
35
|
-
// https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/import/extensions.md
|
|
36
|
-
"import-x/extensions": [
|
|
37
|
-
"error",
|
|
38
|
-
"always",
|
|
39
|
-
{
|
|
40
|
-
ignorePackages: true,
|
|
41
|
-
pattern: {
|
|
42
|
-
js: "always",
|
|
43
|
-
cjs: "always",
|
|
44
|
-
mjs: "always",
|
|
45
|
-
cts: "always",
|
|
46
|
-
mts: "always",
|
|
47
|
-
ts: "always",
|
|
48
|
-
},
|
|
49
|
-
},
|
|
50
|
-
],
|
|
51
|
-
|
|
52
|
-
/* issues */
|
|
53
|
-
|
|
54
|
-
// http://eslint.org/docs/rules/spaced-comment
|
|
55
|
-
// conflicts with typescript triple slash
|
|
56
|
-
"spaced-comment": "off",
|
|
57
|
-
|
|
58
|
-
/* some exported type doesnt work. tsc check that anyway */
|
|
59
|
-
"import-x/named": "off",
|
|
60
|
-
},
|
|
61
|
-
};
|
package/lib/utils/oxlint.js
DELETED
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
import tseslint from "typescript-eslint";
|
|
2
|
-
|
|
3
|
-
/** oxlint plugin name → eslint rule name prefix */
|
|
4
|
-
const eslintRulePrefixes = new Map([
|
|
5
|
-
["eslint", ""],
|
|
6
|
-
["typescript", "@typescript-eslint/"],
|
|
7
|
-
["unicorn", "unicorn/"],
|
|
8
|
-
["import", "import-x/"],
|
|
9
|
-
["node", "n/"],
|
|
10
|
-
["react", "react/"],
|
|
11
|
-
["jsx_a11y", "jsx-a11y/"],
|
|
12
|
-
// JS plugins: the eslint plugins themselves, loaded by oxlint
|
|
13
|
-
["regexp", "regexp/"],
|
|
14
|
-
["@pob", "@pob/"],
|
|
15
|
-
// named "<plugin>-js" when the name is reserved for a native plugin
|
|
16
|
-
["eslint-js", ""],
|
|
17
|
-
["unicorn-js", "unicorn/"],
|
|
18
|
-
["node-js", "n/"],
|
|
19
|
-
["react-js", "react/"],
|
|
20
|
-
]);
|
|
21
|
-
|
|
22
|
-
/** oxlint plugins without eslint equivalent in @pob/eslint-config */
|
|
23
|
-
const oxlintOnlyPlugins = new Set(["oxc", "promise", "vitest"]);
|
|
24
|
-
|
|
25
|
-
/** oxlint implements eslint-plugin-react-hooks rules in its react plugin */
|
|
26
|
-
const reactHooksRules = new Set(["rules-of-hooks", "exhaustive-deps"]);
|
|
27
|
-
|
|
28
|
-
const typescriptEslintRules =
|
|
29
|
-
/** @type {import("eslint").ESLint.Plugin} */ (tseslint.plugin).rules ?? {};
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* eslint core rule → typescript-eslint rules extending it. Type-aware ones are
|
|
33
|
-
* not listed: oxlint's core rule does not replace them (see T1 in
|
|
34
|
-
* docs/oxlint-migration.md).
|
|
35
|
-
*
|
|
36
|
-
* @type {Map<string, string[]>}
|
|
37
|
-
*/
|
|
38
|
-
const typescriptExtensionRules = new Map();
|
|
39
|
-
for (const [ruleName, rule] of Object.entries(typescriptEslintRules)) {
|
|
40
|
-
const docs =
|
|
41
|
-
/** @type {{ extendsBaseRule?: boolean | string; requiresTypeChecking?: boolean } | undefined} */ (
|
|
42
|
-
rule.meta?.docs
|
|
43
|
-
);
|
|
44
|
-
if (!docs?.extendsBaseRule || docs.requiresTypeChecking) continue;
|
|
45
|
-
const baseRuleName =
|
|
46
|
-
docs.extendsBaseRule === true ? ruleName : docs.extendsBaseRule;
|
|
47
|
-
typescriptExtensionRules.set(baseRuleName, [
|
|
48
|
-
...(typescriptExtensionRules.get(baseRuleName) ?? []),
|
|
49
|
-
`@typescript-eslint/${ruleName}`,
|
|
50
|
-
]);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Returns the eslint rule names checked by an oxlint rule, to turn them off in
|
|
55
|
-
* eslint. Rules of plugins other than eslint core must be prefixed with their
|
|
56
|
-
* oxlint plugin name (`typescript/`, `unicorn/`, ...).
|
|
57
|
-
*
|
|
58
|
-
* @param {string} oxlintRuleName
|
|
59
|
-
* @returns {string[]}
|
|
60
|
-
*/
|
|
61
|
-
export const oxlintToEslintRuleNames = (oxlintRuleName) => {
|
|
62
|
-
const slashIndex = oxlintRuleName.indexOf("/");
|
|
63
|
-
const pluginName =
|
|
64
|
-
slashIndex === -1 ? "eslint" : oxlintRuleName.slice(0, slashIndex);
|
|
65
|
-
const ruleName = oxlintRuleName.slice(slashIndex + 1);
|
|
66
|
-
|
|
67
|
-
if (oxlintOnlyPlugins.has(pluginName)) return [];
|
|
68
|
-
if (pluginName === "eslint") {
|
|
69
|
-
return [ruleName, ...(typescriptExtensionRules.get(ruleName) ?? [])];
|
|
70
|
-
}
|
|
71
|
-
if (pluginName === "react" && reactHooksRules.has(ruleName)) {
|
|
72
|
-
return [`react-hooks/${ruleName}`];
|
|
73
|
-
}
|
|
74
|
-
const prefix = eslintRulePrefixes.get(pluginName);
|
|
75
|
-
if (prefix === undefined) {
|
|
76
|
-
throw new Error(
|
|
77
|
-
`Unknown oxlint plugin "${pluginName}" in rule "${oxlintRuleName}"`,
|
|
78
|
-
);
|
|
79
|
-
}
|
|
80
|
-
return [`${prefix}${ruleName}`];
|
|
81
|
-
};
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* Rules of an oxlint config, including its overrides.
|
|
85
|
-
*
|
|
86
|
-
* @param {{ rules?: Record<string, unknown>; overrides?: { rules?: Record<string, unknown> }[] }} config
|
|
87
|
-
* @returns {string[]}
|
|
88
|
-
*/
|
|
89
|
-
export const getOxlintConfigRuleNames = (config) => [
|
|
90
|
-
...Object.keys(config.rules ?? {}),
|
|
91
|
-
...(config.overrides ?? []).flatMap((override) =>
|
|
92
|
-
Object.keys(override.rules ?? {}),
|
|
93
|
-
),
|
|
94
|
-
];
|
|
95
|
-
|
|
96
|
-
const unusedDisableDirectiveRegExp =
|
|
97
|
-
/^Unused eslint-disable directive \(no problems were reported from (.+)\)\.$/;
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Rules named by eslint's "Unused eslint-disable directive" report, undefined
|
|
101
|
-
* for other messages.
|
|
102
|
-
*
|
|
103
|
-
* @param {import("eslint").Linter.LintMessage} message
|
|
104
|
-
* @returns {string[] | undefined}
|
|
105
|
-
*/
|
|
106
|
-
export const getUnusedDisableDirectiveRuleNames = (message) => {
|
|
107
|
-
if (message.ruleId !== null) return undefined;
|
|
108
|
-
const match = unusedDisableDirectiveRegExp.exec(message.message);
|
|
109
|
-
if (!match) return undefined;
|
|
110
|
-
return [...match[1].matchAll(/'([^']+)'/g)].map(([, ruleName]) => ruleName);
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Drops eslint's "Unused eslint-disable directive" reports for rules checked
|
|
115
|
-
* by oxlint, so projects keep their `eslint-disable` comments of moved rules:
|
|
116
|
-
* oxlint honors them, and `eslint --fix` no longer deletes them. Unused
|
|
117
|
-
* directives of other rules are still reported and fixed.
|
|
118
|
-
*
|
|
119
|
-
* @param {Set<string>} oxlintEslintRuleNames eslint names of the rules checked
|
|
120
|
-
* by oxlint
|
|
121
|
-
* @returns {import("eslint").Linter.Processor}
|
|
122
|
-
*/
|
|
123
|
-
export const createOxlintDisableDirectivesProcessor = (
|
|
124
|
-
oxlintEslintRuleNames,
|
|
125
|
-
) => ({
|
|
126
|
-
meta: { name: "@pob/eslint-config/oxlint-disable-directives" },
|
|
127
|
-
supportsAutofix: true,
|
|
128
|
-
preprocess: (text) => [text],
|
|
129
|
-
postprocess: (messageLists) =>
|
|
130
|
-
messageLists.flat().filter((message) => {
|
|
131
|
-
const ruleNames = getUnusedDisableDirectiveRuleNames(message);
|
|
132
|
-
return !ruleNames?.every((ruleName) =>
|
|
133
|
-
oxlintEslintRuleNames.has(ruleName),
|
|
134
|
-
);
|
|
135
|
-
}),
|
|
136
|
-
});
|
package/lib/utils/oxlint.test.js
DELETED
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import pobPlugin from "@pob/eslint-plugin";
|
|
3
|
-
import { Linter } from "eslint";
|
|
4
|
-
import { builtinRules } from "eslint/use-at-your-own-risk";
|
|
5
|
-
import importPlugin from "eslint-plugin-import-x";
|
|
6
|
-
import nodePlugin from "eslint-plugin-n";
|
|
7
|
-
import regexpPlugin from "eslint-plugin-regexp";
|
|
8
|
-
import eslintPluginUnicorn from "eslint-plugin-unicorn";
|
|
9
|
-
import tseslint from "typescript-eslint";
|
|
10
|
-
import oxlintBaseConfig from "../../oxlint/base.json" with { type: "json" };
|
|
11
|
-
import oxlintNodeConfig from "../../oxlint/node.json" with { type: "json" };
|
|
12
|
-
import oxlintTypescriptConfig from "../../oxlint/typescript.json" with { type: "json" };
|
|
13
|
-
import {
|
|
14
|
-
createOxlintDisableDirectivesProcessor,
|
|
15
|
-
getOxlintConfigRuleNames,
|
|
16
|
-
getUnusedDisableDirectiveRuleNames,
|
|
17
|
-
oxlintToEslintRuleNames,
|
|
18
|
-
} from "./oxlint.js";
|
|
19
|
-
|
|
20
|
-
/** @type {import("eslint").Linter.Config} */
|
|
21
|
-
const baseConfig = {
|
|
22
|
-
linterOptions: { reportUnusedDisableDirectives: "error" },
|
|
23
|
-
rules: { "no-debugger": "off", "no-unreachable": "error" },
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
describe("getUnusedDisableDirectiveRuleNames", () => {
|
|
27
|
-
// fails if an eslint upgrade rewords the message the processor relies on
|
|
28
|
-
it.each([
|
|
29
|
-
["no-debugger", ["no-debugger"]],
|
|
30
|
-
["no-debugger, no-console", ["no-debugger", "no-console"]],
|
|
31
|
-
[
|
|
32
|
-
"no-debugger, no-console, no-alert",
|
|
33
|
-
["no-debugger", "no-console", "no-alert"],
|
|
34
|
-
],
|
|
35
|
-
])(
|
|
36
|
-
"parses eslint's report for eslint-disable-next-line %s",
|
|
37
|
-
(ruleNames, expected) => {
|
|
38
|
-
const messages = new Linter().verify(
|
|
39
|
-
`// eslint-disable-next-line ${ruleNames}\nexport const a = 1;\n`,
|
|
40
|
-
baseConfig,
|
|
41
|
-
);
|
|
42
|
-
expect(messages).toHaveLength(1);
|
|
43
|
-
expect(getUnusedDisableDirectiveRuleNames(messages[0])).toEqual(expected);
|
|
44
|
-
},
|
|
45
|
-
);
|
|
46
|
-
|
|
47
|
-
it("ignores other messages", () => {
|
|
48
|
-
const messages = new Linter().verify(
|
|
49
|
-
"export function f() {\n return;\n f();\n}\n",
|
|
50
|
-
baseConfig,
|
|
51
|
-
);
|
|
52
|
-
expect(messages.map(({ ruleId }) => ruleId)).toEqual(["no-unreachable"]);
|
|
53
|
-
expect(getUnusedDisableDirectiveRuleNames(messages[0])).toBeUndefined();
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
describe("createOxlintDisableDirectivesProcessor", () => {
|
|
58
|
-
/** @type {import("eslint").Linter.Config[]} */
|
|
59
|
-
const configs = [
|
|
60
|
-
baseConfig,
|
|
61
|
-
{
|
|
62
|
-
files: ["**/*.js"],
|
|
63
|
-
processor: createOxlintDisableDirectivesProcessor(
|
|
64
|
-
new Set(["no-debugger"]),
|
|
65
|
-
),
|
|
66
|
-
},
|
|
67
|
-
];
|
|
68
|
-
const source = [
|
|
69
|
-
"// eslint-disable-next-line no-debugger",
|
|
70
|
-
"export const a = 1;",
|
|
71
|
-
"// eslint-disable-next-line no-unreachable",
|
|
72
|
-
"export const b = 1;",
|
|
73
|
-
"",
|
|
74
|
-
].join("\n");
|
|
75
|
-
|
|
76
|
-
it("drops unused directive reports of rules checked by oxlint only", () => {
|
|
77
|
-
const messages = new Linter().verify(source, configs, "file.js");
|
|
78
|
-
expect(
|
|
79
|
-
messages.map((message) => getUnusedDisableDirectiveRuleNames(message)),
|
|
80
|
-
).toEqual([["no-unreachable"]]);
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
it("keeps the comments of rules checked by oxlint on --fix", () => {
|
|
84
|
-
const { output } = new Linter().verifyAndFix(source, configs, "file.js");
|
|
85
|
-
// eslint's fix leaves the indentation of the removed comment
|
|
86
|
-
expect(output.split("\n").map((line) => line.trim())).toEqual([
|
|
87
|
-
"// eslint-disable-next-line no-debugger",
|
|
88
|
-
"export const a = 1;",
|
|
89
|
-
"",
|
|
90
|
-
"export const b = 1;",
|
|
91
|
-
"",
|
|
92
|
-
]);
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
describe("oxlintToEslintRuleNames", () => {
|
|
97
|
-
it.each([
|
|
98
|
-
["no-debugger", ["no-debugger"]],
|
|
99
|
-
["eslint/no-debugger", ["no-debugger"]],
|
|
100
|
-
["typescript/no-explicit-any", ["@typescript-eslint/no-explicit-any"]],
|
|
101
|
-
["unicorn/prefer-node-protocol", ["unicorn/prefer-node-protocol"]],
|
|
102
|
-
["import/no-cycle", ["import-x/no-cycle"]],
|
|
103
|
-
["node/no-path-concat", ["n/no-path-concat"]],
|
|
104
|
-
["jsx_a11y/alt-text", ["jsx-a11y/alt-text"]],
|
|
105
|
-
["react/jsx-key", ["react/jsx-key"]],
|
|
106
|
-
["react/rules-of-hooks", ["react-hooks/rules-of-hooks"]],
|
|
107
|
-
["react/exhaustive-deps", ["react-hooks/exhaustive-deps"]],
|
|
108
|
-
["react-js/jsx-no-leaked-render", ["react/jsx-no-leaked-render"]],
|
|
109
|
-
["eslint-js/camelcase", ["camelcase"]],
|
|
110
|
-
["eslint-js/dot-notation", ["dot-notation"]],
|
|
111
|
-
["unicorn-js/prefer-switch", ["unicorn/prefer-switch"]],
|
|
112
|
-
["node-js/no-deprecated-api", ["n/no-deprecated-api"]],
|
|
113
|
-
["oxc/no-map-spread", []],
|
|
114
|
-
["promise/valid-params", []],
|
|
115
|
-
["vitest/no-focused-tests", []],
|
|
116
|
-
])("maps %s", (oxlintRuleName, eslintRuleNames) => {
|
|
117
|
-
expect(oxlintToEslintRuleNames(oxlintRuleName)).toEqual(eslintRuleNames);
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
it.each([
|
|
121
|
-
["no-unused-vars", ["no-unused-vars", "@typescript-eslint/no-unused-vars"]],
|
|
122
|
-
[
|
|
123
|
-
"eslint/no-redeclare",
|
|
124
|
-
["no-redeclare", "@typescript-eslint/no-redeclare"],
|
|
125
|
-
],
|
|
126
|
-
[
|
|
127
|
-
"no-useless-constructor",
|
|
128
|
-
["no-useless-constructor", "@typescript-eslint/no-useless-constructor"],
|
|
129
|
-
],
|
|
130
|
-
])(
|
|
131
|
-
"maps extension rule %s to the core and typescript-eslint rules",
|
|
132
|
-
(oxlintRuleName, eslintRuleNames) => {
|
|
133
|
-
expect(oxlintToEslintRuleNames(oxlintRuleName)).toEqual(eslintRuleNames);
|
|
134
|
-
},
|
|
135
|
-
);
|
|
136
|
-
|
|
137
|
-
it.each([
|
|
138
|
-
["require-await"],
|
|
139
|
-
["dot-notation"],
|
|
140
|
-
["no-implied-eval"],
|
|
141
|
-
["no-throw-literal"],
|
|
142
|
-
])("keeps type-aware extension rules of %s in eslint", (oxlintRuleName) => {
|
|
143
|
-
expect(oxlintToEslintRuleNames(oxlintRuleName)).toEqual([oxlintRuleName]);
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
it("throws on unknown plugins", () => {
|
|
147
|
-
expect(() => oxlintToEslintRuleNames("jsdoc/check-tag-names")).toThrow(
|
|
148
|
-
'Unknown oxlint plugin "jsdoc" in rule "jsdoc/check-tag-names"',
|
|
149
|
-
);
|
|
150
|
-
});
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
describe("getOxlintConfigRuleNames", () => {
|
|
154
|
-
it("lists the rules of the config and of its overrides", () => {
|
|
155
|
-
expect(
|
|
156
|
-
getOxlintConfigRuleNames({
|
|
157
|
-
rules: { "no-debugger": "error" },
|
|
158
|
-
overrides: [
|
|
159
|
-
{ rules: { "typescript/no-namespace": "error" } },
|
|
160
|
-
{ rules: {} },
|
|
161
|
-
],
|
|
162
|
-
}),
|
|
163
|
-
).toEqual(["no-debugger", "typescript/no-namespace"]);
|
|
164
|
-
});
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
describe("oxlint/*.json", () => {
|
|
168
|
-
/** @type {[string, unknown][]} */
|
|
169
|
-
const plugins = [
|
|
170
|
-
["@typescript-eslint/", tseslint.plugin],
|
|
171
|
-
["unicorn/", eslintPluginUnicorn],
|
|
172
|
-
["import-x/", importPlugin],
|
|
173
|
-
["n/", nodePlugin],
|
|
174
|
-
["regexp/", regexpPlugin],
|
|
175
|
-
["@pob/", pobPlugin],
|
|
176
|
-
];
|
|
177
|
-
const eslintRuleNames = new Set([
|
|
178
|
-
...builtinRules.keys(),
|
|
179
|
-
...plugins.flatMap(([prefix, plugin]) =>
|
|
180
|
-
Object.keys(
|
|
181
|
-
/** @type {import("eslint").ESLint.Plugin} */ (plugin).rules ?? {},
|
|
182
|
-
).map((ruleName) => `${prefix}${ruleName}`),
|
|
183
|
-
),
|
|
184
|
-
]);
|
|
185
|
-
|
|
186
|
-
it.each([
|
|
187
|
-
...new Set(
|
|
188
|
-
[oxlintBaseConfig, oxlintNodeConfig, oxlintTypescriptConfig].flatMap(
|
|
189
|
-
(config) => getOxlintConfigRuleNames(config),
|
|
190
|
-
),
|
|
191
|
-
),
|
|
192
|
-
])("%s turns off existing eslint rules", (oxlintRuleName) => {
|
|
193
|
-
const mapped = oxlintToEslintRuleNames(oxlintRuleName);
|
|
194
|
-
expect(mapped.length).toBeGreaterThan(0);
|
|
195
|
-
expect(mapped.filter((name) => !eslintRuleNames.has(name))).toEqual([]);
|
|
196
|
-
});
|
|
197
|
-
});
|