@pob/eslint-config 67.5.0 → 67.6.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,8 @@
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 oxlintTypescriptConfig from "../oxlint/typescript.json" with { type: "json" };
5
6
  import baseConfigs from "./_base.js";
6
7
  import baseCommonjsConfig from "./base/commonjs.js";
7
8
  import baseModuleConfig from "./base/module.js";
@@ -28,6 +29,7 @@ import typescriptRulesConfig from "./rules/typescript.js";
28
29
  import { apply } from "./utils/apply.js";
29
30
  import {
30
31
  createOxlintDisableDirectivesProcessor,
32
+ getOxlintConfigRuleNames,
31
33
  oxlintToEslintRuleNames,
32
34
  } from "./utils/oxlint.js";
33
35
 
@@ -51,15 +53,30 @@ if (!tsFiles) {
51
53
 
52
54
  const extensions = "{js,cjs,mjs}";
53
55
 
56
+ const oxlintrcPath = path.resolve(".oxlintrc.json");
57
+ const oxlintrc = fs.existsSync(oxlintrcPath)
58
+ ? fs.readFileSync(oxlintrcPath, "utf8")
59
+ : undefined;
60
+
61
+ // typescript.json is extended by TypeScript projects only, once regenerated by
62
+ // pob: until then its rules stay in eslint.
63
+ const oxlintTypescript =
64
+ oxlintrc?.includes("@pob/eslint-config/oxlint/typescript.json") ?? false;
65
+
66
+ // the shared oxlint configs the project extends
67
+ const oxlintSharedConfigs = oxlintrc
68
+ ? [oxlintBaseConfig, ...(oxlintTypescript ? [oxlintTypescriptConfig] : [])]
69
+ : [];
70
+
54
71
  const oxlintEslintRuleNames = new Set(
55
- Object.keys(oxlintConfig.rules).flatMap((ruleName) =>
56
- oxlintToEslintRuleNames(ruleName),
57
- ),
72
+ oxlintSharedConfigs
73
+ .flatMap((config) => getOxlintConfigRuleNames(config))
74
+ .flatMap((ruleName) => oxlintToEslintRuleNames(ruleName)),
58
75
  );
59
76
 
60
77
  // turns off the rules checked by oxlint, must be applied last. Only when the
61
78
  // project runs oxlint, so the rules are still checked by eslint otherwise.
62
- const oxlintConfigs = fs.existsSync(path.resolve(".oxlintrc.json"))
79
+ const oxlintConfigs = oxlintrc
63
80
  ? [
64
81
  {
65
82
  name: "@pob/eslint-config/oxlint",
@@ -74,9 +91,55 @@ const oxlintConfigs = fs.existsSync(path.resolve(".oxlintrc.json"))
74
91
  oxlintEslintRuleNames,
75
92
  ),
76
93
  },
94
+ // oxlint runs every type-aware rule: eslint no longer needs to build the
95
+ // TypeScript program, its most expensive part
96
+ ...(oxlintTypescript
97
+ ? [
98
+ {
99
+ name: "@pob/eslint-config/oxlint-typescript",
100
+ files: [`**/*.${tsExtensions}`],
101
+ languageOptions: {
102
+ parserOptions: { project: false, projectService: false },
103
+ },
104
+ },
105
+ ]
106
+ : []),
77
107
  ]
78
108
  : [];
79
109
 
110
+ /**
111
+ * Removes the rules checked by oxlint from configs applied after
112
+ * `oxlintConfigs`, like the overrides a project selects. Their oxlint
113
+ * counterparts are extended in .oxlintrc.json (`oxlint/allow-unsafe.json`,
114
+ * ...).
115
+ *
116
+ * @template {{ rules?: Record<string, unknown> }} T
117
+ * @param {T[]} configs
118
+ * @returns {T[]}
119
+ */
120
+ const withoutOxlintRules = (configs) =>
121
+ configs.map((config) =>
122
+ config.rules
123
+ ? {
124
+ ...config,
125
+ rules: Object.fromEntries(
126
+ Object.entries(config.rules).filter(
127
+ ([ruleName]) => !oxlintEslintRuleNames.has(ruleName),
128
+ ),
129
+ ),
130
+ }
131
+ : config,
132
+ );
133
+
134
+ // without the TypeScript program, only the import-x settings are left
135
+ const {
136
+ languageOptions: _toolsProjectLanguageOptions,
137
+ ...toolsProjectSettings
138
+ } = toolsProjectConfig;
139
+ const toolsProjectConfigs = [
140
+ oxlintTypescript ? toolsProjectSettings : toolsProjectConfig,
141
+ ];
142
+
80
143
  const testFiles = [
81
144
  `**/*.{test,test-e2e,spec}.${extensions}`,
82
145
  `**/__tests__/**/*.${extensions}`,
@@ -211,22 +274,22 @@ export default {
211
274
  node: [...nodeModule, ...oxlintConfigs],
212
275
 
213
276
  allowImplicitReturnType: applyTs({
214
- configs: [allowImplicitReturnTypeConfig],
277
+ configs: withoutOxlintRules([allowImplicitReturnTypeConfig]),
215
278
  }),
216
279
 
217
280
  allowUnsafe: applyTs({
218
- configs: [allowUnsafeConfig],
281
+ configs: withoutOxlintRules([allowUnsafeConfig]),
219
282
  }),
220
283
 
221
284
  allowUnsafeAsWarn: applyTs({
222
- configs: [allowUnsafeAsWarnConfig],
285
+ configs: withoutOxlintRules([allowUnsafeAsWarnConfig]),
223
286
  }),
224
287
 
225
288
  app: applyTs({
226
- configs: [appConfig],
289
+ configs: withoutOxlintRules([appConfig]),
227
290
  }),
228
291
 
229
- monorepo: [toolsProjectConfig],
230
- toolsProject: [toolsProjectConfig],
292
+ monorepo: toolsProjectConfigs,
293
+ toolsProject: toolsProjectConfigs,
231
294
  },
232
295
  };
@@ -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,7 @@ 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 typescriptConfigPath = path.join(oxlintConfigsDir, "typescript.json");
8
9
  // this repo's config, the options are not in base.json so projects keep
9
10
  // eslint-disable comments working
10
11
  const rootConfig = JSON.parse(
@@ -18,8 +19,8 @@ const rootConfig = JSON.parse(
18
19
  * Lints `source` in a project whose .oxlintrc.json extends base.json, like the
19
20
  * one written by pob.
20
21
  */
21
- const lint = async (cwd, source) => {
22
- await writeFile(path.join(cwd, "file.js"), source);
22
+ const lint = async (cwd, source, fileName = "file.js") => {
23
+ await writeFile(path.join(cwd, fileName), source);
23
24
  return lintWithOxlint(cwd);
24
25
  };
25
26
 
@@ -31,15 +32,20 @@ const summarize = (diagnostics) =>
31
32
 
32
33
  /**
33
34
  * @param {Record<string, unknown>} config
35
+ * @param {string[]} extendsPaths
34
36
  */
35
- const useProject = (config) => {
37
+ const useProject = (config, extendsPaths = [baseConfigPath]) => {
36
38
  const project = { cwd: "" };
37
39
 
38
40
  beforeAll(async () => {
39
41
  project.cwd = await mkdtemp(path.join(tmpdir(), "pob-oxlint-"));
40
42
  await writeFile(
41
43
  path.join(project.cwd, ".oxlintrc.json"),
42
- JSON.stringify({ ...config, extends: [baseConfigPath] }),
44
+ JSON.stringify({ ...config, extends: extendsPaths }),
45
+ );
46
+ await writeFile(
47
+ path.join(project.cwd, "tsconfig.json"),
48
+ JSON.stringify({ compilerOptions: { strict: true } }),
43
49
  );
44
50
  });
45
51
 
@@ -79,6 +85,90 @@ describe("oxlint/base.json", () => {
79
85
  });
80
86
  });
81
87
 
88
+ describe("oxlint/typescript.json", () => {
89
+ const project = useProject({}, [baseConfigPath, typescriptConfigPath]);
90
+ const floatingPromise = "Promise.resolve();\nexport {};\n";
91
+
92
+ // documented as root-only, but inherited through extends
93
+ it("enables type-aware linting", async () => {
94
+ expect(
95
+ summarize(await lint(project.cwd, floatingPromise, "file.ts")),
96
+ ).toEqual([{ line: 1, rule: "typescript(no-floating-promises)" }]);
97
+ });
98
+
99
+ // oxlint applies type-aware rules to the .js files of a TypeScript project
100
+ it("scopes rules to TypeScript files", async () => {
101
+ await rm(path.join(project.cwd, "file.ts"));
102
+ expect(await lint(project.cwd, floatingPromise, "file.js")).toEqual([]);
103
+ });
104
+ });
105
+
106
+ // projects extend them after typescript.json, like the matching eslint configs
107
+ describe.each([
108
+ {
109
+ fileName: "",
110
+ expected: [
111
+ "error typescript(explicit-function-return-type)",
112
+ "error typescript(explicit-module-boundary-types)",
113
+ "error typescript(no-unsafe-member-access)",
114
+ "error typescript(no-unsafe-return)",
115
+ ],
116
+ },
117
+ {
118
+ fileName: "app.json",
119
+ expected: [
120
+ "error typescript(no-unsafe-member-access)",
121
+ "error typescript(no-unsafe-return)",
122
+ ],
123
+ },
124
+ {
125
+ fileName: "allow-implicit-return-type.json",
126
+ expected: [
127
+ "error typescript(no-unsafe-member-access)",
128
+ "error typescript(no-unsafe-return)",
129
+ ],
130
+ },
131
+ {
132
+ fileName: "allow-unsafe.json",
133
+ expected: [
134
+ "error typescript(explicit-function-return-type)",
135
+ "error typescript(explicit-module-boundary-types)",
136
+ ],
137
+ },
138
+ {
139
+ fileName: "allow-unsafe-as-warn.json",
140
+ expected: [
141
+ "error typescript(explicit-function-return-type)",
142
+ "error typescript(explicit-module-boundary-types)",
143
+ "warning typescript(no-unsafe-member-access)",
144
+ "warning typescript(no-unsafe-return)",
145
+ ],
146
+ },
147
+ ])("oxlint/typescript.json with $fileName", ({ fileName, expected }) => {
148
+ const project = useProject({}, [
149
+ baseConfigPath,
150
+ typescriptConfigPath,
151
+ ...(fileName ? [path.join(oxlintConfigsDir, fileName)] : []),
152
+ ]);
153
+
154
+ it("overrides the rules", async () => {
155
+ const diagnostics = await lint(
156
+ project.cwd,
157
+ "export function f(value: any) {\n return value.a;\n}\n",
158
+ "file.ts",
159
+ );
160
+ expect(
161
+ [
162
+ ...new Set(
163
+ diagnostics
164
+ .filter(({ code }) => /\((?:explicit-|no-unsafe-)/.test(code ?? ""))
165
+ .map(({ code, severity }) => `${severity} ${code}`),
166
+ ),
167
+ ].toSorted(),
168
+ ).toEqual(expected);
169
+ });
170
+ });
171
+
82
172
  describe("root .oxlintrc.json options", () => {
83
173
  const project = useProject({ options: rootConfig.options });
84
174
 
@@ -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
+ }
@@ -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
+ }
package/oxlint/base.json CHANGED
@@ -3,6 +3,66 @@
3
3
  "correctness": "off"
4
4
  },
5
5
  "rules": {
6
- "no-debugger": "error"
7
- }
6
+ "default-param-last": "error",
7
+ "max-params": [
8
+ "warn",
9
+ {
10
+ "max": 3
11
+ }
12
+ ],
13
+ "no-array-constructor": "error",
14
+ "no-debugger": "error",
15
+ "no-dupe-class-members": "error",
16
+ "no-empty-function": [
17
+ "error",
18
+ {
19
+ "allow": ["arrowFunctions", "functions", "methods"]
20
+ }
21
+ ],
22
+ "no-loop-func": "error",
23
+ "no-unused-expressions": [
24
+ "error",
25
+ {
26
+ "allowShortCircuit": false,
27
+ "allowTaggedTemplates": false,
28
+ "allowTernary": false,
29
+ "enforceForJSX": false,
30
+ "ignoreDirectives": false
31
+ }
32
+ ],
33
+ "no-unused-vars": [
34
+ "error",
35
+ {
36
+ "args": "none",
37
+ "caughtErrors": "none",
38
+ "ignoreClassWithStaticInitBlock": false,
39
+ "ignoreRestSiblings": true,
40
+ "ignoreUsingDeclarations": false,
41
+ "reportUsedIgnorePattern": false,
42
+ "vars": "all"
43
+ }
44
+ ],
45
+ "no-use-before-define": [
46
+ "error",
47
+ {
48
+ "allowNamedExports": false,
49
+ "classes": true,
50
+ "enums": true,
51
+ "functions": true,
52
+ "ignoreTypeReferences": true,
53
+ "typedefs": true,
54
+ "variables": true
55
+ }
56
+ ],
57
+ "no-useless-constructor": "error",
58
+ "require-await": "error"
59
+ },
60
+ "overrides": [
61
+ {
62
+ "files": ["**/*.{ts,cts,mts,tsx}"],
63
+ "rules": {
64
+ "require-await": "off"
65
+ }
66
+ }
67
+ ]
8
68
  }
@@ -0,0 +1,188 @@
1
+ {
2
+ "options": {
3
+ "typeAware": true
4
+ },
5
+ "overrides": [
6
+ {
7
+ "files": ["**/*.{ts,cts,mts,tsx}"],
8
+ "rules": {
9
+ "typescript/adjacent-overload-signatures": "error",
10
+ "typescript/array-type": "error",
11
+ "typescript/await-thenable": "error",
12
+ "typescript/ban-ts-comment": [
13
+ "error",
14
+ {
15
+ "minimumDescriptionLength": 3,
16
+ "ts-check": true,
17
+ "ts-expect-error": "allow-with-description",
18
+ "ts-ignore": true,
19
+ "ts-nocheck": true
20
+ }
21
+ ],
22
+ "typescript/ban-tslint-comment": "error",
23
+ "typescript/class-literal-property-style": "error",
24
+ "typescript/consistent-generic-constructors": "error",
25
+ "typescript/consistent-indexed-object-style": "error",
26
+ "typescript/consistent-type-assertions": [
27
+ "error",
28
+ {
29
+ "arrayLiteralTypeAssertions": "allow",
30
+ "assertionStyle": "as",
31
+ "objectLiteralTypeAssertions": "allow-as-parameter"
32
+ }
33
+ ],
34
+ "typescript/consistent-type-definitions": "error",
35
+ "typescript/consistent-type-exports": "error",
36
+ "typescript/consistent-type-imports": "error",
37
+ "typescript/dot-notation": [
38
+ "error",
39
+ {
40
+ "allowIndexSignaturePropertyAccess": false,
41
+ "allowKeywords": true,
42
+ "allowPattern": "",
43
+ "allowPrivateClassPropertyAccess": false,
44
+ "allowProtectedClassPropertyAccess": false
45
+ }
46
+ ],
47
+ "typescript/explicit-function-return-type": [
48
+ "error",
49
+ {
50
+ "allowConciseArrowFunctionExpressionsStartingWithVoid": false,
51
+ "allowDirectConstAssertionInArrowFunctions": true,
52
+ "allowExpressions": true,
53
+ "allowFunctionsWithoutTypeParameters": false,
54
+ "allowHigherOrderFunctions": true,
55
+ "allowIIFEs": false,
56
+ "allowTypedFunctionExpressions": true,
57
+ "allowedNames": []
58
+ }
59
+ ],
60
+ "typescript/explicit-module-boundary-types": "error",
61
+ "typescript/method-signature-style": "error",
62
+ "typescript/no-array-delete": "error",
63
+ "typescript/no-base-to-string": "error",
64
+ "typescript/no-confusing-non-null-assertion": "error",
65
+ "typescript/no-confusing-void-expression": "warn",
66
+ "typescript/no-deprecated": "error",
67
+ "typescript/no-duplicate-enum-values": "error",
68
+ "typescript/no-duplicate-type-constituents": "error",
69
+ "typescript/no-dynamic-delete": "error",
70
+ "typescript/no-empty-object-type": "error",
71
+ "typescript/no-explicit-any": "warn",
72
+ "typescript/no-extra-non-null-assertion": "error",
73
+ "typescript/no-floating-promises": "error",
74
+ "typescript/no-for-in-array": "error",
75
+ "typescript/no-implied-eval": "error",
76
+ "typescript/no-import-type-side-effects": "error",
77
+ "typescript/no-inferrable-types": "error",
78
+ "typescript/no-invalid-void-type": "error",
79
+ "typescript/no-meaningless-void-operator": "error",
80
+ "typescript/no-misused-new": "error",
81
+ "typescript/no-misused-promises": "error",
82
+ "typescript/no-misused-spread": "error",
83
+ "typescript/no-mixed-enums": "error",
84
+ "typescript/no-namespace": "error",
85
+ "typescript/no-non-null-asserted-nullish-coalescing": "error",
86
+ "typescript/no-non-null-asserted-optional-chain": "error",
87
+ "typescript/no-non-null-assertion": "warn",
88
+ "typescript/no-redundant-type-constituents": "warn",
89
+ "typescript/no-this-alias": "error",
90
+ "typescript/no-unnecessary-boolean-literal-compare": "error",
91
+ "typescript/no-unnecessary-condition": "warn",
92
+ "typescript/no-unnecessary-qualifier": "error",
93
+ "typescript/no-unnecessary-template-expression": "error",
94
+ "typescript/no-unnecessary-type-assertion": "error",
95
+ "typescript/no-unnecessary-type-constraint": "error",
96
+ "typescript/no-unnecessary-type-conversion": "error",
97
+ "typescript/no-unnecessary-type-parameters": "warn",
98
+ "typescript/no-unsafe-argument": "error",
99
+ "typescript/no-unsafe-assignment": "error",
100
+ "typescript/no-unsafe-call": "error",
101
+ "typescript/no-unsafe-declaration-merging": "error",
102
+ "typescript/no-unsafe-enum-comparison": "error",
103
+ "typescript/no-unsafe-function-type": "error",
104
+ "typescript/no-unsafe-member-access": "error",
105
+ "typescript/no-unsafe-return": "error",
106
+ "typescript/no-unsafe-unary-minus": "error",
107
+ "typescript/no-useless-default-assignment": "error",
108
+ "typescript/no-useless-empty-export": "error",
109
+ "typescript/no-wrapper-object-types": "error",
110
+ "typescript/non-nullable-type-assertion-style": "error",
111
+ "typescript/only-throw-error": "error",
112
+ "typescript/parameter-properties": "error",
113
+ "typescript/prefer-as-const": "error",
114
+ "typescript/prefer-enum-initializers": "error",
115
+ "typescript/prefer-find": "error",
116
+ "typescript/prefer-function-type": "error",
117
+ "typescript/prefer-literal-enum-member": "error",
118
+ "typescript/prefer-namespace-keyword": "error",
119
+ "typescript/prefer-optional-chain": "error",
120
+ "typescript/prefer-promise-reject-errors": "error",
121
+ "typescript/prefer-reduce-type-parameter": "error",
122
+ "typescript/prefer-regexp-exec": "error",
123
+ "typescript/prefer-return-this-type": "error",
124
+ "typescript/prefer-string-starts-ends-with": "error",
125
+ "typescript/related-getter-setter-pairs": "error",
126
+ "typescript/require-await": "error",
127
+ "typescript/restrict-plus-operands": [
128
+ "error",
129
+ {
130
+ "allowAny": false,
131
+ "allowBoolean": false,
132
+ "allowNullish": false,
133
+ "allowNumberAndString": false,
134
+ "allowRegExp": false
135
+ }
136
+ ],
137
+ "typescript/restrict-template-expressions": [
138
+ "error",
139
+ {
140
+ "allow": [
141
+ {
142
+ "from": "lib",
143
+ "name": ["Error", "URL", "URLSearchParams"]
144
+ }
145
+ ],
146
+ "allowAny": false,
147
+ "allowArray": false,
148
+ "allowBoolean": true,
149
+ "allowNever": false,
150
+ "allowNullish": false,
151
+ "allowNumber": true,
152
+ "allowRegExp": false
153
+ }
154
+ ],
155
+ "typescript/return-await": ["error", "error-handling-correctness-only"],
156
+ "typescript/switch-exhaustiveness-check": "error",
157
+ "typescript/triple-slash-reference": "error",
158
+ "typescript/unified-signatures": "warn",
159
+ "typescript/use-unknown-in-catch-callback-variable": "error"
160
+ }
161
+ },
162
+ {
163
+ "files": [
164
+ "**/*.test.{ts,cts,mts,tsx}",
165
+ "**/*.test-e2e.{ts,cts,mts,tsx}",
166
+ "**/__tests__/**/*.{ts,cts,mts,tsx}",
167
+ "**/__mocks__/**/*.{ts,cts,mts,tsx}"
168
+ ],
169
+ "rules": {
170
+ "typescript/explicit-function-return-type": "off",
171
+ "typescript/no-floating-promises": [
172
+ "error",
173
+ {
174
+ "allowForKnownSafeCalls": [
175
+ {
176
+ "from": "package",
177
+ "name": ["it", "describe", "test"],
178
+ "package": "node:test"
179
+ }
180
+ ]
181
+ }
182
+ ],
183
+ "typescript/no-unsafe-member-access": "off",
184
+ "typescript/no-unsafe-return": "off"
185
+ }
186
+ }
187
+ ]
188
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pob/eslint-config",
3
- "version": "67.5.0",
3
+ "version": "67.6.0",
4
4
  "description": "eslint config files",
5
5
  "keywords": [],
6
6
  "homepage": "https://github.com/christophehurpeau/pob",
@@ -16,7 +16,12 @@
16
16
  },
17
17
  "files": [
18
18
  "lib",
19
+ "oxlint/allow-implicit-return-type.json",
20
+ "oxlint/allow-unsafe-as-warn.json",
21
+ "oxlint/allow-unsafe.json",
22
+ "oxlint/app.json",
19
23
  "oxlint/base.json",
24
+ "oxlint/typescript.json",
20
25
  "utils.js"
21
26
  ],
22
27
  "type": "module",
@@ -28,7 +33,12 @@
28
33
  "./lib/rules/code-quality": "./lib/rules/code-quality.js",
29
34
  "./lib/rules/errors": "./lib/rules/errors.js",
30
35
  "./lib/rules/style": "./lib/rules/style.js",
36
+ "./oxlint/allow-implicit-return-type.json": "./oxlint/allow-implicit-return-type.json",
37
+ "./oxlint/allow-unsafe.json": "./oxlint/allow-unsafe.json",
38
+ "./oxlint/allow-unsafe-as-warn.json": "./oxlint/allow-unsafe-as-warn.json",
39
+ "./oxlint/app.json": "./oxlint/app.json",
31
40
  "./oxlint/base.json": "./oxlint/base.json",
41
+ "./oxlint/typescript.json": "./oxlint/typescript.json",
32
42
  "./utils": "./utils.js",
33
43
  "./package.json": "./package.json"
34
44
  },
@@ -47,7 +57,7 @@
47
57
  "eslint-plugin-regexp": "^3.1.0",
48
58
  "eslint-plugin-unicorn": "^64.0.0",
49
59
  "typescript-eslint": "^8.63.0",
50
- "@pob/eslint-plugin": "66.2.0"
60
+ "@pob/eslint-plugin": "66.3.0"
51
61
  },
52
62
  "devDependencies": {
53
63
  "@types/node": "24.13.3",
@@ -75,6 +85,6 @@
75
85
  "scripts": {
76
86
  "lint": "pnpm run lint:oxlint && pnpm run lint:eslint",
77
87
  "lint:eslint": "pnpm --dir '../..' exec eslint --quiet '@pob/eslint-config'",
78
- "lint:oxlint": "pnpm --dir '../..' exec oxlint '@pob/eslint-config'"
88
+ "lint:oxlint": "pnpm --dir '../..' exec oxlint --quiet '@pob/eslint-config'"
79
89
  }
80
90
  }