@pob/eslint-config 67.5.0 → 67.7.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/index.js CHANGED
@@ -1,7 +1,9 @@
1
1
  import fs from "node:fs";
2
2
  import path from "node:path";
3
3
  import tseslint from "typescript-eslint";
4
- import oxlintConfig from "../oxlint/base.json" with { type: "json" };
4
+ import oxlintBaseConfig from "../oxlint/base.json" with { type: "json" };
5
+ import oxlintNodeConfig from "../oxlint/node.json" with { type: "json" };
6
+ import oxlintTypescriptConfig from "../oxlint/typescript.json" with { type: "json" };
5
7
  import baseConfigs from "./_base.js";
6
8
  import baseCommonjsConfig from "./base/commonjs.js";
7
9
  import baseModuleConfig from "./base/module.js";
@@ -28,6 +30,7 @@ import typescriptRulesConfig from "./rules/typescript.js";
28
30
  import { apply } from "./utils/apply.js";
29
31
  import {
30
32
  createOxlintDisableDirectivesProcessor,
33
+ getOxlintConfigRuleNames,
31
34
  oxlintToEslintRuleNames,
32
35
  } from "./utils/oxlint.js";
33
36
 
@@ -51,15 +54,39 @@ if (!tsFiles) {
51
54
 
52
55
  const extensions = "{js,cjs,mjs}";
53
56
 
57
+ const oxlintrcPath = path.resolve(".oxlintrc.json");
58
+ const oxlintrc = fs.existsSync(oxlintrcPath)
59
+ ? fs.readFileSync(oxlintrcPath, "utf8")
60
+ : undefined;
61
+
62
+ // typescript.json is extended by TypeScript projects only, once regenerated by
63
+ // pob: until then its rules stay in eslint.
64
+ const oxlintTypescript =
65
+ oxlintrc?.includes("@pob/eslint-config/oxlint/typescript.json") ?? false;
66
+
67
+ // node.json is extended by projects using the node configs, once regenerated
68
+ // by pob: until then its rules stay in eslint.
69
+ const oxlintNode =
70
+ oxlintrc?.includes("@pob/eslint-config/oxlint/node.json") ?? false;
71
+
72
+ // the shared oxlint configs the project extends
73
+ const oxlintSharedConfigs = oxlintrc
74
+ ? [
75
+ oxlintBaseConfig,
76
+ ...(oxlintNode ? [oxlintNodeConfig] : []),
77
+ ...(oxlintTypescript ? [oxlintTypescriptConfig] : []),
78
+ ]
79
+ : [];
80
+
54
81
  const oxlintEslintRuleNames = new Set(
55
- Object.keys(oxlintConfig.rules).flatMap((ruleName) =>
56
- oxlintToEslintRuleNames(ruleName),
57
- ),
82
+ oxlintSharedConfigs
83
+ .flatMap((config) => getOxlintConfigRuleNames(config))
84
+ .flatMap((ruleName) => oxlintToEslintRuleNames(ruleName)),
58
85
  );
59
86
 
60
87
  // turns off the rules checked by oxlint, must be applied last. Only when the
61
88
  // project runs oxlint, so the rules are still checked by eslint otherwise.
62
- const oxlintConfigs = fs.existsSync(path.resolve(".oxlintrc.json"))
89
+ const oxlintConfigs = oxlintrc
63
90
  ? [
64
91
  {
65
92
  name: "@pob/eslint-config/oxlint",
@@ -74,9 +101,55 @@ const oxlintConfigs = fs.existsSync(path.resolve(".oxlintrc.json"))
74
101
  oxlintEslintRuleNames,
75
102
  ),
76
103
  },
104
+ // oxlint runs every type-aware rule: eslint no longer needs to build the
105
+ // TypeScript program, its most expensive part
106
+ ...(oxlintTypescript
107
+ ? [
108
+ {
109
+ name: "@pob/eslint-config/oxlint-typescript",
110
+ files: [`**/*.${tsExtensions}`],
111
+ languageOptions: {
112
+ parserOptions: { project: false, projectService: false },
113
+ },
114
+ },
115
+ ]
116
+ : []),
77
117
  ]
78
118
  : [];
79
119
 
120
+ /**
121
+ * Removes the rules checked by oxlint from configs applied after
122
+ * `oxlintConfigs`, like the overrides a project selects. Their oxlint
123
+ * counterparts are extended in .oxlintrc.json (`oxlint/allow-unsafe.json`,
124
+ * ...).
125
+ *
126
+ * @template {{ rules?: Record<string, unknown> }} T
127
+ * @param {T[]} configs
128
+ * @returns {T[]}
129
+ */
130
+ const withoutOxlintRules = (configs) =>
131
+ configs.map((config) =>
132
+ config.rules
133
+ ? {
134
+ ...config,
135
+ rules: Object.fromEntries(
136
+ Object.entries(config.rules).filter(
137
+ ([ruleName]) => !oxlintEslintRuleNames.has(ruleName),
138
+ ),
139
+ ),
140
+ }
141
+ : config,
142
+ );
143
+
144
+ // without the TypeScript program, only the import-x settings are left
145
+ const {
146
+ languageOptions: _toolsProjectLanguageOptions,
147
+ ...toolsProjectSettings
148
+ } = toolsProjectConfig;
149
+ const toolsProjectConfigs = [
150
+ oxlintTypescript ? toolsProjectSettings : toolsProjectConfig,
151
+ ];
152
+
80
153
  const testFiles = [
81
154
  `**/*.{test,test-e2e,spec}.${extensions}`,
82
155
  `**/__tests__/**/*.${extensions}`,
@@ -211,22 +284,22 @@ export default {
211
284
  node: [...nodeModule, ...oxlintConfigs],
212
285
 
213
286
  allowImplicitReturnType: applyTs({
214
- configs: [allowImplicitReturnTypeConfig],
287
+ configs: withoutOxlintRules([allowImplicitReturnTypeConfig]),
215
288
  }),
216
289
 
217
290
  allowUnsafe: applyTs({
218
- configs: [allowUnsafeConfig],
291
+ configs: withoutOxlintRules([allowUnsafeConfig]),
219
292
  }),
220
293
 
221
294
  allowUnsafeAsWarn: applyTs({
222
- configs: [allowUnsafeAsWarnConfig],
295
+ configs: withoutOxlintRules([allowUnsafeAsWarnConfig]),
223
296
  }),
224
297
 
225
298
  app: applyTs({
226
- configs: [appConfig],
299
+ configs: withoutOxlintRules([appConfig]),
227
300
  }),
228
301
 
229
- monorepo: [toolsProjectConfig],
230
- toolsProject: [toolsProjectConfig],
302
+ monorepo: toolsProjectConfigs,
303
+ toolsProject: toolsProjectConfigs,
231
304
  },
232
305
  };
@@ -0,0 +1,56 @@
1
+ import path from "node:path";
2
+ import { describe, expect, it } from "vitest";
3
+ import { ESLint } from "eslint";
4
+ import pobConfig from "./index.js";
5
+
6
+ const rootDir = path.resolve(import.meta.dirname, "../../..");
7
+
8
+ // index.js reads the .oxlintrc.json of cwd: tests run from the root of this
9
+ // repo, whose .oxlintrc.json extends oxlint/typescript.json
10
+ describe("with oxlint/typescript.json extended", () => {
11
+ const { configs } = pobConfig;
12
+
13
+ const calculateConfig = (overrideConfig) =>
14
+ new ESLint({
15
+ cwd: rootDir,
16
+ overrideConfigFile: true,
17
+ overrideConfig,
18
+ }).calculateConfigForFile(path.join(rootDir, "src/file.ts"));
19
+
20
+ it("runs from the root of the repo", () => {
21
+ expect(process.cwd()).toBe(rootDir);
22
+ });
23
+
24
+ it("does not build the TypeScript program", async () => {
25
+ const config = await calculateConfig([
26
+ ...configs.node,
27
+ ...configs.monorepo,
28
+ ]);
29
+ expect(config.languageOptions.parserOptions).toMatchObject({
30
+ project: false,
31
+ projectService: false,
32
+ });
33
+ });
34
+
35
+ it("enables no type-aware rule", async () => {
36
+ const config = await calculateConfig([
37
+ ...configs.node,
38
+ ...configs.allowUnsafeAsWarn,
39
+ ...configs.allowImplicitReturnType,
40
+ ...configs.app,
41
+ ...configs.monorepo,
42
+ ]);
43
+ const typeAwareRules = Object.entries(config.rules)
44
+ .filter(([, [severity]]) => severity !== 0)
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([]);
55
+ });
56
+ });
@@ -1,28 +1,12 @@
1
- import {
2
- mkdir,
3
- mkdtemp,
4
- readFile,
5
- readdir,
6
- rm,
7
- writeFile,
8
- } from "node:fs/promises";
9
- import { tmpdir } from "node:os";
1
+ import { readFile, readdir } from "node:fs/promises";
10
2
  import path from "node:path";
11
- import { afterAll, beforeAll, describe, expect, it } from "vitest";
12
- import { ESLint } from "eslint";
3
+ import { describe, expect, it } from "vitest";
13
4
  import {
14
- getDiagnosticRuleName,
15
5
  getEnabledOxlintConfigRules,
16
- lintWithOxlint,
17
- oxlintConfigsDir,
18
6
  toCanonicalOxlintRuleName,
19
7
  } from "./test-utils/oxlint.js";
20
- import { oxlintToEslintRuleNames } from "./utils/oxlint.js";
21
- import pobConfig from "./index.js";
22
8
 
23
- const packageDir = path.resolve(import.meta.dirname, "..");
24
- const rootDir = path.resolve(packageDir, "../..");
25
- const testLintDir = path.join(packageDir, "test-lint");
9
+ const testLintDir = path.resolve(import.meta.dirname, "../test-lint");
26
10
 
27
11
  /**
28
12
  * Rules named by the oxlint-disable directives of `source`, as `plugin/rule`.
@@ -41,127 +25,29 @@ const getDirectiveRules = (source) =>
41
25
  .map((rule) => toCanonicalOxlintRuleName(rule)),
42
26
  );
43
27
 
44
- /**
45
- * Removes eslint and oxlint directives, keeping line numbers.
46
- *
47
- * @param {string} source
48
- */
49
- const stripDirectives = (source) =>
50
- source
51
- .replaceAll(
52
- /\/\*\s*(?:eslint|oxlint)-(?:disable|enable)[\s\S]*?\*\//g,
53
- (comment) => comment.replaceAll(/[^\n]/g, ""),
54
- )
55
- .replaceAll(/\/\/\s*(?:eslint|oxlint)-(?:disable|enable)[^\n]*/g, "");
56
-
57
- /**
58
- * @param {number[]} lines
59
- */
60
- const sortLines = (lines) => lines.toSorted((a, b) => a - b);
61
-
62
- const enabledOxlintRules = getEnabledOxlintConfigRules();
63
-
64
28
  const testLintDirents = await readdir(testLintDir, {
65
29
  recursive: true,
66
30
  withFileTypes: true,
67
31
  });
68
32
 
69
- /** @type {{ relativePath: string; source: string; oxlintRules: Set<string> }[]} */
70
- const fixtures = await Promise.all(
33
+ const fixturesDirectiveRules = await Promise.all(
71
34
  testLintDirents
72
35
  .filter((dirent) => dirent.isFile())
73
- .map(async (dirent) => {
74
- const filePath = path.join(dirent.parentPath, dirent.name);
75
- const source = await readFile(filePath, "utf8");
76
- return {
77
- relativePath: path.relative(packageDir, filePath),
78
- source,
79
- oxlintRules: new Set(getDirectiveRules(source)),
80
- };
81
- }),
36
+ .map(async (dirent) =>
37
+ getDirectiveRules(
38
+ await readFile(path.join(dirent.parentPath, dirent.name), "utf8"),
39
+ ),
40
+ ),
82
41
  );
83
-
84
- /**
85
- * @param {string} oxlintRule
86
- */
87
- const getRuleFixtures = (oxlintRule) =>
88
- fixtures.filter((fixture) => fixture.oxlintRules.has(oxlintRule));
42
+ const directiveRules = new Set(fixturesDirectiveRules.flat());
89
43
 
90
44
  describe("oxlint rules fixtures", () => {
91
45
  // with P1 directive options, `pnpm lint:oxlint` fails if the rule stops
92
46
  // reporting on the fixture
93
- it.each(enabledOxlintRules)(
47
+ it.each(getEnabledOxlintConfigRules())(
94
48
  "%s has a test-lint fixture with an oxlint-disable directive",
95
49
  (oxlintRule) => {
96
- expect(getRuleFixtures(oxlintRule)).not.toEqual([]);
97
- },
98
- );
99
- });
100
-
101
- describe("oxlint and eslint parity", () => {
102
- /** @type {string} */
103
- let oxlintCwd;
104
- /** @type {Map<string, { rule: string | undefined; line: number }[]>} */
105
- const oxlintResults = new Map();
106
- const eslint = new ESLint({
107
- cwd: rootDir,
108
- overrideConfigFile: true,
109
- overrideConfig: pobConfig.configs.node.filter(
110
- (config) => config.name !== "@pob/eslint-config/oxlint",
111
- ),
112
- });
113
-
114
- beforeAll(async () => {
115
- oxlintCwd = await mkdtemp(path.join(tmpdir(), "pob-oxlint-parity-"));
116
- await writeFile(
117
- path.join(oxlintCwd, ".oxlintrc.json"),
118
- JSON.stringify({ extends: [path.join(oxlintConfigsDir, "base.json")] }),
119
- );
120
- for (const fixture of fixtures) {
121
- if (fixture.oxlintRules.size === 0) continue;
122
- const filePath = path.join(oxlintCwd, fixture.relativePath);
123
- await mkdir(path.dirname(filePath), { recursive: true });
124
- await writeFile(filePath, stripDirectives(fixture.source));
125
- }
126
- for (const diagnostic of await lintWithOxlint(oxlintCwd)) {
127
- const results = oxlintResults.get(diagnostic.filename) ?? [];
128
- results.push({
129
- rule: getDiagnosticRuleName(diagnostic),
130
- line: diagnostic.labels[0].span.line,
131
- });
132
- oxlintResults.set(diagnostic.filename, results);
133
- }
134
- });
135
-
136
- afterAll(async () => {
137
- if (oxlintCwd) await rm(oxlintCwd, { recursive: true, force: true });
138
- });
139
-
140
- it.each(
141
- enabledOxlintRules.flatMap((oxlintRule) =>
142
- getRuleFixtures(oxlintRule).map((fixture) => ({ oxlintRule, fixture })),
143
- ),
144
- )(
145
- "$oxlintRule reports the same lines as eslint in $fixture.relativePath",
146
- async ({ oxlintRule, fixture }) => {
147
- const eslintRuleNames = new Set(oxlintToEslintRuleNames(oxlintRule));
148
- const [eslintResult] = await eslint.lintText(
149
- stripDirectives(fixture.source),
150
- { filePath: path.join(packageDir, fixture.relativePath) },
151
- );
152
- const eslintLines = sortLines(
153
- eslintResult.messages
154
- .filter(({ ruleId }) => ruleId && eslintRuleNames.has(ruleId))
155
- .map(({ line }) => line),
156
- );
157
- const oxlintLines = sortLines(
158
- (oxlintResults.get(fixture.relativePath) ?? [])
159
- .filter(({ rule }) => rule === oxlintRule)
160
- .map(({ line }) => line),
161
- );
162
-
163
- expect(eslintLines).not.toEqual([]);
164
- expect(oxlintLines).toEqual(eslintLines);
50
+ expect(directiveRules.has(oxlintRule)).toBe(true);
165
51
  },
166
52
  );
167
53
  });
@@ -5,6 +5,8 @@ import { afterAll, beforeAll, describe, expect, it } from "vitest";
5
5
  import { lintWithOxlint, oxlintConfigsDir } from "./test-utils/oxlint.js";
6
6
 
7
7
  const baseConfigPath = path.join(oxlintConfigsDir, "base.json");
8
+ const nodeConfigPath = path.join(oxlintConfigsDir, "node.json");
9
+ const typescriptConfigPath = path.join(oxlintConfigsDir, "typescript.json");
8
10
  // this repo's config, the options are not in base.json so projects keep
9
11
  // eslint-disable comments working
10
12
  const rootConfig = JSON.parse(
@@ -18,8 +20,8 @@ const rootConfig = JSON.parse(
18
20
  * Lints `source` in a project whose .oxlintrc.json extends base.json, like the
19
21
  * one written by pob.
20
22
  */
21
- const lint = async (cwd, source) => {
22
- await writeFile(path.join(cwd, "file.js"), source);
23
+ const lint = async (cwd, source, fileName = "file.js") => {
24
+ await writeFile(path.join(cwd, fileName), source);
23
25
  return lintWithOxlint(cwd);
24
26
  };
25
27
 
@@ -31,15 +33,20 @@ const summarize = (diagnostics) =>
31
33
 
32
34
  /**
33
35
  * @param {Record<string, unknown>} config
36
+ * @param {string[]} extendsPaths
34
37
  */
35
- const useProject = (config) => {
38
+ const useProject = (config, extendsPaths = [baseConfigPath]) => {
36
39
  const project = { cwd: "" };
37
40
 
38
41
  beforeAll(async () => {
39
42
  project.cwd = await mkdtemp(path.join(tmpdir(), "pob-oxlint-"));
40
43
  await writeFile(
41
44
  path.join(project.cwd, ".oxlintrc.json"),
42
- JSON.stringify({ ...config, extends: [baseConfigPath] }),
45
+ JSON.stringify({ ...config, extends: extendsPaths }),
46
+ );
47
+ await writeFile(
48
+ path.join(project.cwd, "tsconfig.json"),
49
+ JSON.stringify({ compilerOptions: { strict: true } }),
43
50
  );
44
51
  });
45
52
 
@@ -79,6 +86,107 @@ describe("oxlint/base.json", () => {
79
86
  });
80
87
  });
81
88
 
89
+ describe("oxlint/node.json", () => {
90
+ const project = useProject({}, [baseConfigPath, nodeConfigPath]);
91
+ const commonjs = '"use strict";\n';
92
+
93
+ it("reports CommonJS in ES modules", async () => {
94
+ expect(summarize(await lint(project.cwd, commonjs, "file.js"))).toEqual([
95
+ { line: 1, rule: "unicorn(prefer-module)" },
96
+ ]);
97
+ });
98
+
99
+ // like the eslint node configs, which apply nodeCommonjs rules to .cjs files
100
+ it("allows CommonJS in .cjs files", async () => {
101
+ await rm(path.join(project.cwd, "file.js"));
102
+ expect(await lint(project.cwd, commonjs, "file.cjs")).toEqual([]);
103
+ });
104
+ });
105
+
106
+ describe("oxlint/typescript.json", () => {
107
+ const project = useProject({}, [baseConfigPath, typescriptConfigPath]);
108
+ const floatingPromise = "Promise.resolve();\nexport {};\n";
109
+
110
+ // documented as root-only, but inherited through extends
111
+ it("enables type-aware linting", async () => {
112
+ expect(
113
+ summarize(await lint(project.cwd, floatingPromise, "file.ts")),
114
+ ).toEqual([{ line: 1, rule: "typescript(no-floating-promises)" }]);
115
+ });
116
+
117
+ // oxlint applies type-aware rules to the .js files of a TypeScript project
118
+ it("scopes rules to TypeScript files", async () => {
119
+ await rm(path.join(project.cwd, "file.ts"));
120
+ expect(await lint(project.cwd, floatingPromise, "file.js")).toEqual([]);
121
+ });
122
+ });
123
+
124
+ // projects extend them after typescript.json, like the matching eslint configs
125
+ describe.each([
126
+ {
127
+ fileName: "",
128
+ expected: [
129
+ "error typescript(explicit-function-return-type)",
130
+ "error typescript(explicit-module-boundary-types)",
131
+ "error typescript(no-unsafe-member-access)",
132
+ "error typescript(no-unsafe-return)",
133
+ ],
134
+ },
135
+ {
136
+ fileName: "app.json",
137
+ expected: [
138
+ "error typescript(no-unsafe-member-access)",
139
+ "error typescript(no-unsafe-return)",
140
+ ],
141
+ },
142
+ {
143
+ fileName: "allow-implicit-return-type.json",
144
+ expected: [
145
+ "error typescript(no-unsafe-member-access)",
146
+ "error typescript(no-unsafe-return)",
147
+ ],
148
+ },
149
+ {
150
+ fileName: "allow-unsafe.json",
151
+ expected: [
152
+ "error typescript(explicit-function-return-type)",
153
+ "error typescript(explicit-module-boundary-types)",
154
+ ],
155
+ },
156
+ {
157
+ fileName: "allow-unsafe-as-warn.json",
158
+ expected: [
159
+ "error typescript(explicit-function-return-type)",
160
+ "error typescript(explicit-module-boundary-types)",
161
+ "warning typescript(no-unsafe-member-access)",
162
+ "warning typescript(no-unsafe-return)",
163
+ ],
164
+ },
165
+ ])("oxlint/typescript.json with $fileName", ({ fileName, expected }) => {
166
+ const project = useProject({}, [
167
+ baseConfigPath,
168
+ typescriptConfigPath,
169
+ ...(fileName ? [path.join(oxlintConfigsDir, fileName)] : []),
170
+ ]);
171
+
172
+ it("overrides the rules", async () => {
173
+ const diagnostics = await lint(
174
+ project.cwd,
175
+ "export function f(value: any) {\n return value.a;\n}\n",
176
+ "file.ts",
177
+ );
178
+ expect(
179
+ [
180
+ ...new Set(
181
+ diagnostics
182
+ .filter(({ code }) => /\((?:explicit-|no-unsafe-)/.test(code ?? ""))
183
+ .map(({ code, severity }) => `${severity} ${code}`),
184
+ ),
185
+ ].toSorted(),
186
+ ).toEqual(expected);
187
+ });
188
+ });
189
+
82
190
  describe("root .oxlintrc.json options", () => {
83
191
  const project = useProject({ options: rootConfig.options });
84
192
 
@@ -6,15 +6,9 @@ import { promisify } from "node:util";
6
6
 
7
7
  const execFileAsync = promisify(execFile);
8
8
 
9
- const oxlintPackageJsonUrl = import.meta.resolve("oxlint/package.json");
10
- const { default: oxlintPkg } = await import(oxlintPackageJsonUrl, {
11
- with: { type: "json" },
12
- });
9
+ // the bin used by projects, which also locates tsgolint for type-aware rules
13
10
  const oxlintBinPath = fileURLToPath(
14
- new URL(
15
- typeof oxlintPkg.bin === "string" ? oxlintPkg.bin : oxlintPkg.bin.oxlint,
16
- oxlintPackageJsonUrl,
17
- ),
11
+ new URL("./bin/oxlint.js", import.meta.resolve("@pob/root/package.json")),
18
12
  );
19
13
 
20
14
  export const oxlintConfigsDir = fileURLToPath(
@@ -91,17 +85,6 @@ export const listOxlintRules = async (cwd) => {
91
85
  export const toCanonicalOxlintRuleName = (ruleName) =>
92
86
  ruleName.includes("/") ? ruleName : `eslint/${ruleName}`;
93
87
 
94
- /**
95
- * `plugin/rule` name of a diagnostic, from its code like `jsx-a11y(alt-text)`.
96
- * Undefined for diagnostics not reported by a rule (unused directives).
97
- *
98
- * @param {OxlintDiagnostic} diagnostic
99
- */
100
- export const getDiagnosticRuleName = (diagnostic) => {
101
- const match = diagnostic.code && /^([^(]+)\(([^)]+)\)$/.exec(diagnostic.code);
102
- return match ? `${match[1].replaceAll("-", "_")}/${match[2]}` : undefined;
103
- };
104
-
105
88
  /**
106
89
  * @param {unknown} ruleEntry
107
90
  */
@@ -22,7 +22,7 @@ const typescriptEslintRules =
22
22
 
23
23
  /**
24
24
  * eslint core rule → typescript-eslint rules extending it. Type-aware ones are
25
- * not listed: oxlint's core rule does not replace them (see TA1 in
25
+ * not listed: oxlint's core rule does not replace them (see T1 in
26
26
  * docs/oxlint-migration.md).
27
27
  *
28
28
  * @type {Map<string, string[]>}
@@ -72,6 +72,19 @@ export const oxlintToEslintRuleNames = (oxlintRuleName) => {
72
72
  return [`${prefix}${ruleName}`];
73
73
  };
74
74
 
75
+ /**
76
+ * Rules of an oxlint config, including its overrides.
77
+ *
78
+ * @param {{ rules?: Record<string, unknown>; overrides?: { rules?: Record<string, unknown> }[] }} config
79
+ * @returns {string[]}
80
+ */
81
+ export const getOxlintConfigRuleNames = (config) => [
82
+ ...Object.keys(config.rules ?? {}),
83
+ ...(config.overrides ?? []).flatMap((override) =>
84
+ Object.keys(override.rules ?? {}),
85
+ ),
86
+ ];
87
+
75
88
  const unusedDisableDirectiveRegExp =
76
89
  /^Unused eslint-disable directive \(no problems were reported from (.+)\)\.$/;
77
90
 
@@ -5,9 +5,11 @@ import importPlugin from "eslint-plugin-import-x";
5
5
  import nodePlugin from "eslint-plugin-n";
6
6
  import eslintPluginUnicorn from "eslint-plugin-unicorn";
7
7
  import tseslint from "typescript-eslint";
8
- import oxlintConfig from "../../oxlint/base.json" with { type: "json" };
8
+ import oxlintBaseConfig from "../../oxlint/base.json" with { type: "json" };
9
+ import oxlintTypescriptConfig from "../../oxlint/typescript.json" with { type: "json" };
9
10
  import {
10
11
  createOxlintDisableDirectivesProcessor,
12
+ getOxlintConfigRuleNames,
11
13
  getUnusedDisableDirectiveRuleNames,
12
14
  oxlintToEslintRuleNames,
13
15
  } from "./oxlint.js";
@@ -140,7 +142,21 @@ describe("oxlintToEslintRuleNames", () => {
140
142
  });
141
143
  });
142
144
 
143
- describe("oxlint/base.json", () => {
145
+ describe("getOxlintConfigRuleNames", () => {
146
+ it("lists the rules of the config and of its overrides", () => {
147
+ expect(
148
+ getOxlintConfigRuleNames({
149
+ rules: { "no-debugger": "error" },
150
+ overrides: [
151
+ { rules: { "typescript/no-namespace": "error" } },
152
+ { rules: {} },
153
+ ],
154
+ }),
155
+ ).toEqual(["no-debugger", "typescript/no-namespace"]);
156
+ });
157
+ });
158
+
159
+ describe("oxlint/*.json", () => {
144
160
  /** @type {[string, unknown][]} */
145
161
  const plugins = [
146
162
  ["@typescript-eslint/", tseslint.plugin],
@@ -157,12 +173,15 @@ describe("oxlint/base.json", () => {
157
173
  ),
158
174
  ]);
159
175
 
160
- it.each(Object.keys(oxlintConfig.rules))(
161
- "%s turns off existing eslint rules",
162
- (oxlintRuleName) => {
163
- const mapped = oxlintToEslintRuleNames(oxlintRuleName);
164
- expect(mapped.length).toBeGreaterThan(0);
165
- expect(mapped.filter((name) => !eslintRuleNames.has(name))).toEqual([]);
166
- },
167
- );
176
+ it.each([
177
+ ...new Set(
178
+ [oxlintBaseConfig, oxlintTypescriptConfig].flatMap((config) =>
179
+ getOxlintConfigRuleNames(config),
180
+ ),
181
+ ),
182
+ ])("%s turns off existing eslint rules", (oxlintRuleName) => {
183
+ const mapped = oxlintToEslintRuleNames(oxlintRuleName);
184
+ expect(mapped.length).toBeGreaterThan(0);
185
+ expect(mapped.filter((name) => !eslintRuleNames.has(name))).toEqual([]);
186
+ });
168
187
  });
@@ -0,0 +1,11 @@
1
+ {
2
+ "overrides": [
3
+ {
4
+ "files": ["**/*.{ts,cts,mts,tsx}"],
5
+ "rules": {
6
+ "typescript/explicit-function-return-type": "off",
7
+ "typescript/explicit-module-boundary-types": "off"
8
+ }
9
+ }
10
+ ]
11
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "overrides": [
3
+ {
4
+ "files": ["**/*.{ts,cts,mts,tsx}"],
5
+ "rules": {
6
+ "typescript/no-unsafe-argument": "warn",
7
+ "typescript/no-unsafe-assignment": "warn",
8
+ "typescript/no-unsafe-call": "warn",
9
+ "typescript/no-unsafe-member-access": "warn",
10
+ "typescript/no-unsafe-return": "warn"
11
+ }
12
+ }
13
+ ]
14
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "overrides": [
3
+ {
4
+ "files": ["**/*.{ts,cts,mts,tsx}"],
5
+ "rules": {
6
+ "typescript/no-unsafe-argument": "off",
7
+ "typescript/no-unsafe-assignment": "off",
8
+ "typescript/no-unsafe-call": "off",
9
+ "typescript/no-unsafe-member-access": "off",
10
+ "typescript/no-unsafe-return": "off"
11
+ }
12
+ }
13
+ ]
14
+ }