@pob/eslint-config 67.14.0 → 68.1.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 +4 -0
- package/oxlint/commonjs.json +17 -0
- package/oxlint/module.json +5 -1
- package/oxlint/node.json +5 -1
- package/package.json +10 -15
- package/lib/base/commonjs.js +0 -12
- 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 -213
- package/lib/plugins/unicorn.js +0 -392
- package/lib/rules/best-practices.js +0 -470
- 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 -26
- package/lib/rules/typescript.js +0 -61
- package/lib/utils/oxlint.js +0 -136
- package/lib/utils/oxlint.test.js +0 -197
package/lib/_base.js
CHANGED
|
@@ -1,16 +1,8 @@
|
|
|
1
|
-
import js from "@eslint/js";
|
|
2
|
-
import pobPlugin from "@pob/eslint-plugin";
|
|
3
1
|
import checkPackageDependenciesConfigs from "./languages/check-package-dependencies.js";
|
|
4
2
|
import jsonConfigs from "./languages/json.js";
|
|
5
|
-
import regexpPluginConfigs from "./plugins/regexp.js";
|
|
6
|
-
import unicornPluginConfigs from "./plugins/unicorn.js";
|
|
7
|
-
import bestPracticesConfig from "./rules/best-practices.js";
|
|
8
|
-
import codeQualityConfig from "./rules/code-quality.js";
|
|
9
|
-
import devOnlyConfig from "./rules/dev-only.js";
|
|
10
|
-
import errorsConfig from "./rules/errors.js";
|
|
11
|
-
import styleConfig from "./rules/style.js";
|
|
12
|
-
import { apply } from "./utils/apply.js";
|
|
13
3
|
|
|
4
|
+
// every other rule of JS and TS files is checked by oxlint, see oxlint/*.json
|
|
5
|
+
/** @type {import("eslint").Linter.Config[]} */
|
|
14
6
|
export default [
|
|
15
7
|
{
|
|
16
8
|
name: "@pob/eslint-config/base/linterOptions",
|
|
@@ -20,12 +12,6 @@ export default [
|
|
|
20
12
|
reportUnusedInlineConfigs: "error",
|
|
21
13
|
},
|
|
22
14
|
},
|
|
23
|
-
{
|
|
24
|
-
name: "@pob/eslint-config/base/pob-plugin",
|
|
25
|
-
plugins: {
|
|
26
|
-
"@pob": pobPlugin,
|
|
27
|
-
},
|
|
28
|
-
},
|
|
29
15
|
{
|
|
30
16
|
name: "@pob/eslint-config/base/ignores",
|
|
31
17
|
ignores: [
|
|
@@ -41,19 +27,23 @@ export default [
|
|
|
41
27
|
},
|
|
42
28
|
...jsonConfigs,
|
|
43
29
|
...checkPackageDependenciesConfigs,
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
30
|
+
{
|
|
31
|
+
name: "@pob/eslint-config/base/code",
|
|
32
|
+
files: ["**/*.{js,cjs,mjs,ts,cts,mts,tsx}"],
|
|
33
|
+
rules: {
|
|
34
|
+
// oxlint reports the BOM at offset 0, where no directive can disable it
|
|
35
|
+
// https://eslint.org/docs/rules/unicode-bom
|
|
36
|
+
"unicode-bom": ["error", "never"],
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
name: "@pob/eslint-config/base/js",
|
|
41
|
+
files: ["**/*.{js,cjs,mjs}"],
|
|
42
|
+
rules: {
|
|
43
|
+
// oxlint ignores /* global */ comments and does not declare undefined.
|
|
44
|
+
// TypeScript files are checked by tsc.
|
|
45
|
+
// https://eslint.org/docs/rules/no-undef
|
|
46
|
+
"no-undef": "error",
|
|
47
|
+
},
|
|
48
|
+
},
|
|
59
49
|
];
|
package/lib/eslint-rules.test.js
CHANGED
|
@@ -6,9 +6,7 @@ describe("eslint rules inventory", () => {
|
|
|
6
6
|
// New rules and newly deprecated ones of eslint and its plugins show up in
|
|
7
7
|
// the snapshot diff on upgrades.
|
|
8
8
|
it("matches the snapshot", async () => {
|
|
9
|
-
const configs = Object.values(pobConfig.configs)
|
|
10
|
-
.flat()
|
|
11
|
-
.filter((config) => config.name !== "@pob/eslint-config/oxlint");
|
|
9
|
+
const configs = Object.values(pobConfig.configs).flat();
|
|
12
10
|
await expect(
|
|
13
11
|
`${JSON.stringify(getEslintRulesStatus(configs), null, 2)}\n`,
|
|
14
12
|
).toMatchFileSnapshot("../inventory/eslint-rules.json");
|
package/lib/index.js
CHANGED
|
@@ -1,43 +1,21 @@
|
|
|
1
1
|
import fs from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
import tseslint from "typescript-eslint";
|
|
4
|
-
import oxlintBaseConfig from "../oxlint/base.json" with { type: "json" };
|
|
5
|
-
import oxlintModuleConfig from "../oxlint/module.json" with { type: "json" };
|
|
6
|
-
import oxlintNodeConfig from "../oxlint/node.json" with { type: "json" };
|
|
7
|
-
import oxlintTypescriptConfig from "../oxlint/typescript.json" with { type: "json" };
|
|
8
3
|
import baseConfigs from "./_base.js";
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import nodePluginCommonjsConfigs from "./node/commonjs.js";
|
|
12
|
-
import nodePluginModuleConfigs from "./node/module.js";
|
|
13
|
-
import nodeTypescriptConfigs from "./node/typescript.js";
|
|
14
|
-
import allowImplicitReturnTypeConfig from "./overrides/allow-implicit-return-type.js";
|
|
15
|
-
import allowUnsafeAsWarnConfig from "./overrides/allow-unsafe-as-warn.js";
|
|
16
|
-
import allowUnsafeConfig from "./overrides/allow-unsafe.js";
|
|
17
|
-
import appConfig from "./overrides/app.js";
|
|
4
|
+
import { createNodeConfigs } from "./node.js";
|
|
5
|
+
import devOnlyConfig from "./overrides/dev-only.js";
|
|
18
6
|
import scriptsOverrideConfig from "./overrides/scripts.js";
|
|
19
|
-
import
|
|
20
|
-
testOverrideConfigsWithTypescript,
|
|
21
|
-
testOverrideConfigsWithoutTypescript,
|
|
22
|
-
} from "./overrides/test.js";
|
|
7
|
+
import testOverrideConfig from "./overrides/test.js";
|
|
23
8
|
import toolsProjectConfig from "./overrides/tools-project.js";
|
|
24
|
-
import
|
|
25
|
-
import
|
|
26
|
-
import importPluginModuleConfig from "./plugins/import/import-module.js";
|
|
27
|
-
import typescriptReplaceEslintConfig from "./plugins/typescript-eslint/typescript-eslint-replace-eslint.js";
|
|
28
|
-
import typescriptReplaceUnicornConfig from "./plugins/typescript-eslint/typescript-eslint-replace-unicorn.js";
|
|
29
|
-
import typescriptPluginRulesConfig from "./plugins/typescript-eslint/typescript-eslint-rules.js";
|
|
30
|
-
import typescriptRulesConfig from "./rules/typescript.js";
|
|
9
|
+
import importConfigs from "./plugins/import.js";
|
|
10
|
+
import typescriptConfigs, { tsExtensions } from "./typescript.js";
|
|
31
11
|
import { apply } from "./utils/apply.js";
|
|
32
|
-
import {
|
|
33
|
-
createOxlintDisableDirectivesProcessor,
|
|
34
|
-
getOxlintConfigRuleNames,
|
|
35
|
-
oxlintToEslintRuleNames,
|
|
36
|
-
} from "./utils/oxlint.js";
|
|
37
12
|
|
|
38
|
-
|
|
13
|
+
// eslint only runs what oxlint cannot: JSON files, import-x rules (resolver
|
|
14
|
+
// settings), no-undef, unicode-bom, strict and n/hashbang. Every other rule is
|
|
15
|
+
// in oxlint/*.json, extended by the project's .oxlintrc.json.
|
|
39
16
|
|
|
40
|
-
export
|
|
17
|
+
export { apply } from "./utils/apply.js";
|
|
18
|
+
export { tsExtensions } from "./typescript.js";
|
|
41
19
|
|
|
42
20
|
export const applyTs = (options) =>
|
|
43
21
|
apply({
|
|
@@ -45,333 +23,89 @@ export const applyTs = (options) =>
|
|
|
45
23
|
...options,
|
|
46
24
|
});
|
|
47
25
|
|
|
48
|
-
//
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const
|
|
60
|
-
?
|
|
61
|
-
:
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
export const isOxlintConfigExtended = (configPath) =>
|
|
70
|
-
oxlintrc?.includes(configPath) ?? false;
|
|
71
|
-
|
|
72
|
-
// typescript.json is extended by TypeScript projects only, once regenerated by
|
|
73
|
-
// pob: until then its rules stay in eslint.
|
|
74
|
-
const oxlintTypescript = isOxlintConfigExtended(
|
|
75
|
-
"@pob/eslint-config/oxlint/typescript.json",
|
|
76
|
-
);
|
|
77
|
-
|
|
78
|
-
// module.json is extended by ES module projects (not configs.nodeCommonjs),
|
|
79
|
-
// once regenerated by pob: until then its rules stay in eslint.
|
|
80
|
-
const oxlintModule = isOxlintConfigExtended(
|
|
81
|
-
"@pob/eslint-config/oxlint/module.json",
|
|
82
|
-
);
|
|
83
|
-
|
|
84
|
-
// node.json is extended by projects using the node configs, once regenerated
|
|
85
|
-
// by pob: until then its rules stay in eslint.
|
|
86
|
-
const oxlintNode = isOxlintConfigExtended(
|
|
87
|
-
"@pob/eslint-config/oxlint/node.json",
|
|
88
|
-
);
|
|
89
|
-
|
|
90
|
-
// the shared oxlint configs the project extends
|
|
91
|
-
const oxlintSharedConfigs = oxlintrc
|
|
92
|
-
? [
|
|
93
|
-
oxlintBaseConfig,
|
|
94
|
-
...(oxlintModule ? [oxlintModuleConfig] : []),
|
|
95
|
-
...(oxlintNode ? [oxlintNodeConfig] : []),
|
|
96
|
-
...(oxlintTypescript ? [oxlintTypescriptConfig] : []),
|
|
97
|
-
]
|
|
98
|
-
: [];
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* @param {Parameters<typeof getOxlintConfigRuleNames>[0][]} oxlintConfigs
|
|
102
|
-
*/
|
|
103
|
-
const getOxlintEslintRuleNames = (oxlintConfigs) =>
|
|
104
|
-
new Set(
|
|
105
|
-
oxlintConfigs
|
|
106
|
-
.flatMap((config) => getOxlintConfigRuleNames(config))
|
|
107
|
-
.flatMap((ruleName) => oxlintToEslintRuleNames(ruleName)),
|
|
108
|
-
);
|
|
109
|
-
|
|
110
|
-
const oxlintEslintRuleNames = getOxlintEslintRuleNames(oxlintSharedConfigs);
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Turns off the rules checked by oxlint: those of the shared configs of this
|
|
114
|
-
* package the project extends, and those of `additionalOxlintConfigs` (like
|
|
115
|
-
* `@pob/eslint-config-typescript-react/oxlint/react.json`). Must be applied
|
|
116
|
-
* last. Empty when the project does not run oxlint, so the rules are still
|
|
117
|
-
* checked by eslint.
|
|
118
|
-
*
|
|
119
|
-
* @param {Parameters<typeof getOxlintConfigRuleNames>[0][]} [additionalOxlintConfigs]
|
|
120
|
-
* @returns {import("eslint").Linter.Config[]}
|
|
121
|
-
*/
|
|
122
|
-
export const createOxlintConfigs = (additionalOxlintConfigs = []) => {
|
|
123
|
-
if (!oxlintrc) return [];
|
|
124
|
-
const ruleNames = getOxlintEslintRuleNames([
|
|
125
|
-
...oxlintSharedConfigs,
|
|
126
|
-
...additionalOxlintConfigs,
|
|
127
|
-
]);
|
|
128
|
-
return [
|
|
129
|
-
{
|
|
130
|
-
name: "@pob/eslint-config/oxlint",
|
|
131
|
-
rules: Object.fromEntries(
|
|
132
|
-
[...ruleNames].map((ruleName) => [ruleName, "off"]),
|
|
133
|
-
),
|
|
134
|
-
},
|
|
135
|
-
// replaces the processor of previous configs, so it must know every rule
|
|
136
|
-
// checked by oxlint
|
|
137
|
-
{
|
|
138
|
-
name: "@pob/eslint-config/oxlint-disable-directives",
|
|
139
|
-
files: ["**/*.{js,cjs,mjs,jsx,ts,cts,mts,tsx}"],
|
|
140
|
-
processor: createOxlintDisableDirectivesProcessor(ruleNames),
|
|
141
|
-
},
|
|
142
|
-
];
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
// Without the TypeScript program, a type-aware rule crashes eslint. Computed
|
|
146
|
-
// from the installed typescript-eslint, not from oxlint/typescript.json: a rule
|
|
147
|
-
// added by a newer version is off until moved to oxlint, instead of crashing.
|
|
148
|
-
const typeAwareRuleNames = new Set(
|
|
149
|
-
oxlintTypescript
|
|
150
|
-
? Object.entries(
|
|
151
|
-
/** @type {{ rules?: Record<string, { meta?: { docs?: { requiresTypeChecking?: boolean } } }> }} */ (
|
|
152
|
-
tseslint.plugin
|
|
153
|
-
).rules ?? {},
|
|
154
|
-
)
|
|
155
|
-
.filter(([, rule]) => rule.meta?.docs?.requiresTypeChecking)
|
|
156
|
-
.map(([ruleName]) => `@typescript-eslint/${ruleName}`)
|
|
157
|
-
: [],
|
|
158
|
-
);
|
|
159
|
-
|
|
160
|
-
const oxlintConfigs = [
|
|
161
|
-
...createOxlintConfigs(),
|
|
162
|
-
// oxlint runs every type-aware rule: eslint no longer needs to build the
|
|
163
|
-
// TypeScript program, its most expensive part
|
|
164
|
-
...(oxlintTypescript
|
|
165
|
-
? [
|
|
166
|
-
{
|
|
167
|
-
name: "@pob/eslint-config/oxlint-typescript",
|
|
168
|
-
files: [`**/*.${tsExtensions}`],
|
|
169
|
-
languageOptions: {
|
|
170
|
-
parserOptions: { project: false, projectService: false },
|
|
171
|
-
},
|
|
172
|
-
rules: Object.fromEntries(
|
|
173
|
-
[...typeAwareRuleNames].map((ruleName) => [ruleName, "off"]),
|
|
174
|
-
),
|
|
175
|
-
},
|
|
176
|
-
]
|
|
177
|
-
: []),
|
|
178
|
-
];
|
|
179
|
-
|
|
180
|
-
// n/process-exit-as-throw only feeds eslint's code path analysis, used by rules
|
|
181
|
-
// checked by oxlint (no-unreachable, array-callback-return, ...)
|
|
182
|
-
const oxlintNodeConfigs = oxlintrc
|
|
183
|
-
? [
|
|
184
|
-
{
|
|
185
|
-
name: "@pob/eslint-config/oxlint-node",
|
|
186
|
-
files: ["**/*.{js,cjs,mjs,ts,cts,mts,tsx}"],
|
|
187
|
-
rules: { "n/process-exit-as-throw": "off" },
|
|
188
|
-
},
|
|
189
|
-
]
|
|
190
|
-
: [];
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
* Removes the rules checked by oxlint from configs applied after
|
|
194
|
-
* `oxlintConfigs`, like the overrides a project selects. Their oxlint
|
|
195
|
-
* counterparts are extended in .oxlintrc.json (`oxlint/allow-unsafe.json`,
|
|
196
|
-
* ...).
|
|
197
|
-
*
|
|
198
|
-
* @template {{ rules?: Record<string, unknown> }} T
|
|
199
|
-
* @param {T[]} configs
|
|
200
|
-
* @returns {T[]}
|
|
201
|
-
*/
|
|
202
|
-
const withoutOxlintRules = (configs) =>
|
|
203
|
-
configs.map((config) =>
|
|
204
|
-
config.rules
|
|
205
|
-
? {
|
|
206
|
-
...config,
|
|
207
|
-
rules: Object.fromEntries(
|
|
208
|
-
Object.entries(config.rules).filter(
|
|
209
|
-
([ruleName]) =>
|
|
210
|
-
!oxlintEslintRuleNames.has(ruleName) &&
|
|
211
|
-
!typeAwareRuleNames.has(ruleName),
|
|
212
|
-
),
|
|
213
|
-
),
|
|
214
|
-
}
|
|
215
|
-
: config,
|
|
216
|
-
);
|
|
217
|
-
|
|
218
|
-
// without the TypeScript program, only the import-x settings are left
|
|
219
|
-
const {
|
|
220
|
-
languageOptions: _toolsProjectLanguageOptions,
|
|
221
|
-
...toolsProjectSettings
|
|
222
|
-
} = toolsProjectConfig;
|
|
223
|
-
const toolsProjectConfigs = [
|
|
224
|
-
oxlintTypescript ? toolsProjectSettings : toolsProjectConfig,
|
|
225
|
-
];
|
|
26
|
+
// .js files are CommonJS in packages with "type": "commonjs", like pob
|
|
27
|
+
// generates them
|
|
28
|
+
const packageJsonPath = path.resolve("package.json");
|
|
29
|
+
const isCommonjsPackage =
|
|
30
|
+
fs.existsSync(packageJsonPath) &&
|
|
31
|
+
// oxlint-disable-next-line unicorn-js/prefer-json-parse-buffer
|
|
32
|
+
JSON.parse(fs.readFileSync(packageJsonPath, "utf8")).type === "commonjs";
|
|
33
|
+
|
|
34
|
+
const moduleFiles = isCommonjsPackage
|
|
35
|
+
? ["**/*.{mjs,mts,ts,tsx}"]
|
|
36
|
+
: ["**/*.{js,mjs,mts,ts,tsx}"];
|
|
37
|
+
const commonjsFiles = isCommonjsPackage
|
|
38
|
+
? ["**/*.{js,cjs,cts}"]
|
|
39
|
+
: ["**/*.{cjs,cts}"];
|
|
40
|
+
|
|
41
|
+
const scriptsModuleFiles = isCommonjsPackage
|
|
42
|
+
? ["**/scripts/**/*.mjs"]
|
|
43
|
+
: ["**/scripts/**/*.{js,mjs}"];
|
|
44
|
+
const scriptsCommonjsFiles = isCommonjsPackage
|
|
45
|
+
? ["**/scripts/**/*.{js,cjs}"]
|
|
46
|
+
: ["**/scripts/**/*.cjs"];
|
|
226
47
|
|
|
227
48
|
const testFiles = [
|
|
228
|
-
`**/*.{test,test-e2e,spec}
|
|
229
|
-
`**/__tests__
|
|
230
|
-
`**/__mocks__/**/*.${extensions}`,
|
|
231
|
-
];
|
|
232
|
-
|
|
233
|
-
const tsTestFiles = [
|
|
234
|
-
`**/*.test.${tsExtensions}`,
|
|
235
|
-
`**/*.test-e2e.${tsExtensions}`,
|
|
236
|
-
`**/__tests__/**/*.${tsExtensions}`,
|
|
237
|
-
`**/__mocks__/**/*.${tsExtensions}`,
|
|
238
|
-
];
|
|
239
|
-
|
|
240
|
-
const typescriptConfigs = [
|
|
241
|
-
...applyTs({
|
|
242
|
-
filesOverridesIf: [tsFiles],
|
|
243
|
-
configs: [
|
|
244
|
-
...tseslint.configs.strictTypeChecked,
|
|
245
|
-
typescriptReplaceUnicornConfig,
|
|
246
|
-
typescriptReplaceEslintConfig,
|
|
247
|
-
typescriptPluginRulesConfig,
|
|
248
|
-
typescriptRulesConfig,
|
|
249
|
-
],
|
|
250
|
-
}),
|
|
251
|
-
...apply({
|
|
252
|
-
files: tsTestFiles,
|
|
253
|
-
configs: testOverrideConfigsWithTypescript,
|
|
254
|
-
}),
|
|
255
|
-
];
|
|
256
|
-
|
|
257
|
-
/** @deprecated */
|
|
258
|
-
const nodeCommonjs = [
|
|
259
|
-
...baseConfigs,
|
|
260
|
-
...apply({
|
|
261
|
-
mode: "keep-files-if-exists",
|
|
262
|
-
files: ["**/*.{js,cjs,mjs,mts,ts,tsx,cts}"],
|
|
263
|
-
configs: [
|
|
264
|
-
baseCommonjsConfig,
|
|
265
|
-
...importPluginBaseConfigs,
|
|
266
|
-
importPluginCommonjsConfig,
|
|
267
|
-
...nodePluginCommonjsConfigs,
|
|
268
|
-
],
|
|
269
|
-
}),
|
|
270
|
-
|
|
271
|
-
...apply({
|
|
272
|
-
extensions,
|
|
273
|
-
mode: "directory",
|
|
274
|
-
files: ["**/scripts/"],
|
|
275
|
-
configs: [scriptsOverrideConfig],
|
|
276
|
-
}),
|
|
277
|
-
|
|
278
|
-
...apply({
|
|
279
|
-
files: ["**/*.{mjs,mts}"],
|
|
280
|
-
mode: "keep-files-if-exists",
|
|
281
|
-
configs: [
|
|
282
|
-
baseModuleConfig,
|
|
283
|
-
importPluginModuleConfig,
|
|
284
|
-
...nodePluginModuleConfigs,
|
|
285
|
-
],
|
|
286
|
-
}),
|
|
287
|
-
|
|
288
|
-
...apply({
|
|
289
|
-
files: testFiles,
|
|
290
|
-
configs: testOverrideConfigsWithoutTypescript,
|
|
291
|
-
}),
|
|
49
|
+
`**/*.{test,test-e2e,spec}.{js,cjs,mjs,${tsExtensions.slice(1, -1)}}`,
|
|
50
|
+
`**/{__tests__,__mocks__}/**/*.{js,cjs,mjs,${tsExtensions.slice(1, -1)}}`,
|
|
292
51
|
];
|
|
293
52
|
|
|
53
|
+
/** @type {import("eslint").Linter.Config[]} */
|
|
294
54
|
const baseModule = [
|
|
295
55
|
...baseConfigs,
|
|
296
|
-
...
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
56
|
+
...importConfigs,
|
|
57
|
+
{
|
|
58
|
+
name: "@pob/eslint-config/module",
|
|
59
|
+
files: moduleFiles,
|
|
60
|
+
languageOptions: {
|
|
61
|
+
ecmaVersion: "latest",
|
|
62
|
+
sourceType: "module",
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
name: "@pob/eslint-config/commonjs",
|
|
67
|
+
files: commonjsFiles,
|
|
68
|
+
languageOptions: {
|
|
69
|
+
ecmaVersion: "latest",
|
|
70
|
+
sourceType: "script",
|
|
71
|
+
},
|
|
72
|
+
rules: {
|
|
73
|
+
// https://eslint.org/docs/rules/strict
|
|
74
|
+
strict: ["error", "safe"],
|
|
75
|
+
},
|
|
76
|
+
},
|
|
312
77
|
...typescriptConfigs,
|
|
78
|
+
devOnlyConfig,
|
|
79
|
+
{
|
|
80
|
+
...testOverrideConfig,
|
|
81
|
+
files: testFiles,
|
|
82
|
+
},
|
|
313
83
|
];
|
|
314
84
|
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
files: [
|
|
320
|
-
|
|
321
|
-
}),
|
|
322
|
-
|
|
323
|
-
...apply({
|
|
324
|
-
extensions,
|
|
325
|
-
mode: "directory",
|
|
326
|
-
files: ["**/scripts/"],
|
|
327
|
-
configs: [scriptsOverrideConfig],
|
|
328
|
-
}),
|
|
329
|
-
|
|
330
|
-
...apply({
|
|
331
|
-
mode: "keep-files-if-exists",
|
|
332
|
-
files: ["**/*.{cjs,cts}"],
|
|
333
|
-
configs: [...nodePluginCommonjsConfigs],
|
|
334
|
-
}),
|
|
335
|
-
|
|
336
|
-
...nodeTypescriptConfigs,
|
|
85
|
+
/** @type {import("eslint").Linter.Config[]} */
|
|
86
|
+
const scriptsOverrideConfigs = [
|
|
87
|
+
{
|
|
88
|
+
...scriptsOverrideConfig,
|
|
89
|
+
files: [...scriptsModuleFiles, ...scriptsCommonjsFiles],
|
|
90
|
+
},
|
|
337
91
|
];
|
|
338
92
|
|
|
339
|
-
/**
|
|
340
|
-
|
|
341
|
-
|
|
93
|
+
/** @type {import("eslint").Linter.Config[]} */
|
|
94
|
+
const toolsProjectConfigs = [toolsProjectConfig];
|
|
95
|
+
|
|
342
96
|
export default {
|
|
343
97
|
configs: {
|
|
98
|
+
// scripts run in node
|
|
344
99
|
baseModule: [
|
|
345
100
|
...baseModule,
|
|
346
|
-
...
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
...
|
|
101
|
+
...createNodeConfigs(scriptsModuleFiles, scriptsCommonjsFiles),
|
|
102
|
+
...scriptsOverrideConfigs,
|
|
103
|
+
],
|
|
104
|
+
node: [
|
|
105
|
+
...baseModule,
|
|
106
|
+
...createNodeConfigs(moduleFiles, commonjsFiles),
|
|
107
|
+
...scriptsOverrideConfigs,
|
|
353
108
|
],
|
|
354
|
-
/** @deprecated */
|
|
355
|
-
nodeModule: [...nodeModule, ...oxlintNodeConfigs, ...oxlintConfigs],
|
|
356
|
-
/** @deprecated */
|
|
357
|
-
nodeCommonjs: [...nodeCommonjs, ...oxlintNodeConfigs, ...oxlintConfigs],
|
|
358
|
-
node: [...nodeModule, ...oxlintNodeConfigs, ...oxlintConfigs],
|
|
359
|
-
|
|
360
|
-
allowImplicitReturnType: applyTs({
|
|
361
|
-
configs: withoutOxlintRules([allowImplicitReturnTypeConfig]),
|
|
362
|
-
}),
|
|
363
|
-
|
|
364
|
-
allowUnsafe: applyTs({
|
|
365
|
-
configs: withoutOxlintRules([allowUnsafeConfig]),
|
|
366
|
-
}),
|
|
367
|
-
|
|
368
|
-
allowUnsafeAsWarn: applyTs({
|
|
369
|
-
configs: withoutOxlintRules([allowUnsafeAsWarnConfig]),
|
|
370
|
-
}),
|
|
371
|
-
|
|
372
|
-
app: applyTs({
|
|
373
|
-
configs: withoutOxlintRules([appConfig]),
|
|
374
|
-
}),
|
|
375
109
|
|
|
376
110
|
monorepo: toolsProjectConfigs,
|
|
377
111
|
toolsProject: toolsProjectConfigs,
|
package/lib/index.test.js
CHANGED
|
@@ -5,52 +5,88 @@ import pobConfig from "./index.js";
|
|
|
5
5
|
|
|
6
6
|
const rootDir = path.resolve(import.meta.dirname, "../../..");
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
/**
|
|
9
|
+
* Rules eslint enables for `filePath`: every other rule runs in oxlint, a rule
|
|
10
|
+
* listed here must not be in oxlint/*.json.
|
|
11
|
+
*
|
|
12
|
+
* @param {import("eslint").Linter.Config[]} configs
|
|
13
|
+
* @param {string} filePath
|
|
14
|
+
*/
|
|
15
|
+
const getEnabledRules = async (configs, filePath) => {
|
|
16
|
+
const config = await new ESLint({
|
|
17
|
+
cwd: rootDir,
|
|
18
|
+
overrideConfigFile: true,
|
|
19
|
+
overrideConfig: configs,
|
|
20
|
+
}).calculateConfigForFile(path.join(rootDir, filePath));
|
|
21
|
+
return Object.entries(config.rules)
|
|
22
|
+
.filter(([, [severity]]) => severity !== 0)
|
|
23
|
+
.map(([ruleName]) => ruleName)
|
|
24
|
+
.toSorted();
|
|
25
|
+
};
|
|
12
26
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
27
|
+
const importRules = [
|
|
28
|
+
"import-x/export",
|
|
29
|
+
"import-x/no-extraneous-dependencies",
|
|
30
|
+
"import-x/no-import-module-exports",
|
|
31
|
+
"import-x/no-relative-packages",
|
|
32
|
+
"import-x/no-unresolved",
|
|
33
|
+
"import-x/no-useless-path-segments",
|
|
34
|
+
"import-x/order",
|
|
35
|
+
];
|
|
36
|
+
|
|
37
|
+
// tests run from the root of this repo, an ES module package
|
|
38
|
+
describe("configs.node", () => {
|
|
39
|
+
const { configs } = pobConfig;
|
|
19
40
|
|
|
20
41
|
it("runs from the root of the repo", () => {
|
|
21
42
|
expect(process.cwd()).toBe(rootDir);
|
|
22
43
|
});
|
|
23
44
|
|
|
24
|
-
it(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
45
|
+
it.each([
|
|
46
|
+
["src/file.js", [...importRules, "n/hashbang", "no-undef", "unicode-bom"]],
|
|
47
|
+
[
|
|
48
|
+
"src/file.cjs",
|
|
49
|
+
[...importRules, "n/hashbang", "no-undef", "strict", "unicode-bom"],
|
|
50
|
+
],
|
|
51
|
+
["src/file.ts", [...importRules, "n/hashbang", "unicode-bom"]],
|
|
52
|
+
["src/file.tsx", [...importRules, "n/hashbang", "unicode-bom"]],
|
|
53
|
+
["scripts/file.js", [...importRules, "no-undef", "unicode-bom"]],
|
|
54
|
+
])(
|
|
55
|
+
"enables only the rules oxlint cannot check in %s",
|
|
56
|
+
async (filePath, expected) => {
|
|
57
|
+
expect(await getEnabledRules(configs.node, filePath)).toEqual(
|
|
58
|
+
expected.toSorted(),
|
|
59
|
+
);
|
|
60
|
+
},
|
|
61
|
+
);
|
|
34
62
|
|
|
35
|
-
it("
|
|
36
|
-
const config = await
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
.map(([ruleName]) => ruleName)
|
|
46
|
-
.filter((ruleName) => {
|
|
47
|
-
const slashIndex = ruleName.lastIndexOf("/");
|
|
48
|
-
if (slashIndex === -1) return false;
|
|
49
|
-
const pluginName = ruleName.slice(0, slashIndex);
|
|
50
|
-
const rule =
|
|
51
|
-
config.plugins[pluginName]?.rules?.[ruleName.slice(slashIndex + 1)];
|
|
52
|
-
return Boolean(rule?.meta?.docs?.requiresTypeChecking);
|
|
53
|
-
});
|
|
54
|
-
expect(typeAwareRules).toEqual([]);
|
|
63
|
+
it("parses TypeScript files without the TypeScript program", async () => {
|
|
64
|
+
const config = await new ESLint({
|
|
65
|
+
cwd: rootDir,
|
|
66
|
+
overrideConfigFile: true,
|
|
67
|
+
overrideConfig: configs.node,
|
|
68
|
+
}).calculateConfigForFile(path.join(rootDir, "src/file.ts"));
|
|
69
|
+
expect(config.languageOptions.parser.meta.name).toBe(
|
|
70
|
+
"typescript-eslint/parser",
|
|
71
|
+
);
|
|
72
|
+
expect(config.languageOptions.parserOptions.project).toBeUndefined();
|
|
55
73
|
});
|
|
56
74
|
});
|
|
75
|
+
|
|
76
|
+
describe("configs.baseModule", () => {
|
|
77
|
+
const { configs } = pobConfig;
|
|
78
|
+
|
|
79
|
+
it.each([
|
|
80
|
+
["src/file.js", [...importRules, "no-undef", "unicode-bom"]],
|
|
81
|
+
["src/file.cjs", [...importRules, "no-undef", "strict", "unicode-bom"]],
|
|
82
|
+
["src/file.ts", [...importRules, "unicode-bom"]],
|
|
83
|
+
["scripts/file.js", [...importRules, "no-undef", "unicode-bom"]],
|
|
84
|
+
])(
|
|
85
|
+
"enables only the rules oxlint cannot check in %s",
|
|
86
|
+
async (filePath, expected) => {
|
|
87
|
+
expect(await getEnabledRules(configs.baseModule, filePath)).toEqual(
|
|
88
|
+
expected.toSorted(),
|
|
89
|
+
);
|
|
90
|
+
},
|
|
91
|
+
);
|
|
92
|
+
});
|