@pob/eslint-config 67.4.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.
@@ -0,0 +1,16 @@
1
+ import { describe, expect, it } from "vitest";
2
+ import { getEslintRulesStatus } from "./test-utils/eslintRules.js";
3
+ import pobConfig from "./index.js";
4
+
5
+ describe("eslint rules inventory", () => {
6
+ // New rules and newly deprecated ones of eslint and its plugins show up in
7
+ // the snapshot diff on upgrades.
8
+ it("matches the snapshot", async () => {
9
+ const configs = Object.values(pobConfig.configs)
10
+ .flat()
11
+ .filter((config) => config.name !== "@pob/eslint-config/oxlint");
12
+ await expect(
13
+ `${JSON.stringify(getEslintRulesStatus(configs), null, 2)}\n`,
14
+ ).toMatchFileSnapshot("../inventory/eslint-rules.json");
15
+ });
16
+ });
package/lib/index.js CHANGED
@@ -1,4 +1,8 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
1
3
  import tseslint from "typescript-eslint";
4
+ import oxlintBaseConfig from "../oxlint/base.json" with { type: "json" };
5
+ import oxlintTypescriptConfig from "../oxlint/typescript.json" with { type: "json" };
2
6
  import baseConfigs from "./_base.js";
3
7
  import baseCommonjsConfig from "./base/commonjs.js";
4
8
  import baseModuleConfig from "./base/module.js";
@@ -23,6 +27,11 @@ import typescriptReplaceUnicornConfig from "./plugins/typescript-eslint/typescri
23
27
  import typescriptPluginRulesConfig from "./plugins/typescript-eslint/typescript-eslint-rules.js";
24
28
  import typescriptRulesConfig from "./rules/typescript.js";
25
29
  import { apply } from "./utils/apply.js";
30
+ import {
31
+ createOxlintDisableDirectivesProcessor,
32
+ getOxlintConfigRuleNames,
33
+ oxlintToEslintRuleNames,
34
+ } from "./utils/oxlint.js";
26
35
 
27
36
  export { apply } from "./utils/apply.js";
28
37
 
@@ -44,6 +53,93 @@ if (!tsFiles) {
44
53
 
45
54
  const extensions = "{js,cjs,mjs}";
46
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
+
71
+ const oxlintEslintRuleNames = new Set(
72
+ oxlintSharedConfigs
73
+ .flatMap((config) => getOxlintConfigRuleNames(config))
74
+ .flatMap((ruleName) => oxlintToEslintRuleNames(ruleName)),
75
+ );
76
+
77
+ // turns off the rules checked by oxlint, must be applied last. Only when the
78
+ // project runs oxlint, so the rules are still checked by eslint otherwise.
79
+ const oxlintConfigs = oxlintrc
80
+ ? [
81
+ {
82
+ name: "@pob/eslint-config/oxlint",
83
+ rules: Object.fromEntries(
84
+ [...oxlintEslintRuleNames].map((ruleName) => [ruleName, "off"]),
85
+ ),
86
+ },
87
+ {
88
+ name: "@pob/eslint-config/oxlint-disable-directives",
89
+ files: ["**/*.{js,cjs,mjs,jsx,ts,cts,mts,tsx}"],
90
+ processor: createOxlintDisableDirectivesProcessor(
91
+ oxlintEslintRuleNames,
92
+ ),
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
+ : []),
107
+ ]
108
+ : [];
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
+
47
143
  const testFiles = [
48
144
  `**/*.{test,test-e2e,spec}.${extensions}`,
49
145
  `**/__tests__/**/*.${extensions}`,
@@ -169,30 +265,31 @@ export default {
169
265
  files: ["**/scripts/"],
170
266
  configs: [...nodePluginModuleConfigs, scriptsOverrideConfig],
171
267
  }),
268
+ ...oxlintConfigs,
172
269
  ],
173
270
  /** @deprecated */
174
- nodeModule,
271
+ nodeModule: [...nodeModule, ...oxlintConfigs],
175
272
  /** @deprecated */
176
- nodeCommonjs,
177
- node: nodeModule,
273
+ nodeCommonjs: [...nodeCommonjs, ...oxlintConfigs],
274
+ node: [...nodeModule, ...oxlintConfigs],
178
275
 
179
276
  allowImplicitReturnType: applyTs({
180
- configs: [allowImplicitReturnTypeConfig],
277
+ configs: withoutOxlintRules([allowImplicitReturnTypeConfig]),
181
278
  }),
182
279
 
183
280
  allowUnsafe: applyTs({
184
- configs: [allowUnsafeConfig],
281
+ configs: withoutOxlintRules([allowUnsafeConfig]),
185
282
  }),
186
283
 
187
284
  allowUnsafeAsWarn: applyTs({
188
- configs: [allowUnsafeAsWarnConfig],
285
+ configs: withoutOxlintRules([allowUnsafeAsWarnConfig]),
189
286
  }),
190
287
 
191
288
  app: applyTs({
192
- configs: [appConfig],
289
+ configs: withoutOxlintRules([appConfig]),
193
290
  }),
194
291
 
195
- monorepo: [toolsProjectConfig],
196
- toolsProject: [toolsProjectConfig],
292
+ monorepo: toolsProjectConfigs,
293
+ toolsProject: toolsProjectConfigs,
197
294
  },
198
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
+ });
@@ -0,0 +1,53 @@
1
+ import { readFile, readdir } from "node:fs/promises";
2
+ import path from "node:path";
3
+ import { describe, expect, it } from "vitest";
4
+ import {
5
+ getEnabledOxlintConfigRules,
6
+ toCanonicalOxlintRuleName,
7
+ } from "./test-utils/oxlint.js";
8
+
9
+ const testLintDir = path.resolve(import.meta.dirname, "../test-lint");
10
+
11
+ /**
12
+ * Rules named by the oxlint-disable directives of `source`, as `plugin/rule`.
13
+ *
14
+ * @param {string} source
15
+ */
16
+ const getDirectiveRules = (source) =>
17
+ [...source.matchAll(/oxlint-disable(?:-next-line|-line)?([^\n]*)/g)].flatMap(
18
+ ([, rest]) =>
19
+ rest
20
+ .split("*/")[0]
21
+ .split("--")[0]
22
+ .split(",")
23
+ .map((rule) => rule.trim())
24
+ .filter(Boolean)
25
+ .map((rule) => toCanonicalOxlintRuleName(rule)),
26
+ );
27
+
28
+ const testLintDirents = await readdir(testLintDir, {
29
+ recursive: true,
30
+ withFileTypes: true,
31
+ });
32
+
33
+ const fixturesDirectiveRules = await Promise.all(
34
+ testLintDirents
35
+ .filter((dirent) => dirent.isFile())
36
+ .map(async (dirent) =>
37
+ getDirectiveRules(
38
+ await readFile(path.join(dirent.parentPath, dirent.name), "utf8"),
39
+ ),
40
+ ),
41
+ );
42
+ const directiveRules = new Set(fixturesDirectiveRules.flat());
43
+
44
+ describe("oxlint rules fixtures", () => {
45
+ // with P1 directive options, `pnpm lint:oxlint` fails if the rule stops
46
+ // reporting on the fixture
47
+ it.each(getEnabledOxlintConfigRules())(
48
+ "%s has a test-lint fixture with an oxlint-disable directive",
49
+ (oxlintRule) => {
50
+ expect(directiveRules.has(oxlintRule)).toBe(true);
51
+ },
52
+ );
53
+ });
@@ -0,0 +1,81 @@
1
+ import { readFile } from "node:fs/promises";
2
+ import { beforeAll, describe, expect, it } from "vitest";
3
+ import {
4
+ getEnabledOxlintConfigRules,
5
+ listOxlintRules,
6
+ } from "./test-utils/oxlint.js";
7
+
8
+ /*
9
+ * inventory/oxlint-rules.json records a decision for every oxlint rule of the
10
+ * plugins below, so an oxlint upgrade adding or removing rules fails here.
11
+ * Decisions:
12
+ * - enabled: in oxlint/*.json
13
+ * - migrate: enabled in eslint, to move to oxlint (docs/oxlint-migration.md)
14
+ * - eslint: kept in eslint
15
+ * - evaluate: not used today, to evaluate (Phase 4 of the migration)
16
+ * - rejected: not wanted
17
+ */
18
+ const plugins = new Set([
19
+ "eslint",
20
+ "typescript",
21
+ "unicorn",
22
+ "import",
23
+ "node",
24
+ "react",
25
+ "jsx_a11y",
26
+ "oxc",
27
+ "promise",
28
+ "vitest",
29
+ ]);
30
+ const decisions = new Set([
31
+ "enabled",
32
+ "migrate",
33
+ "eslint",
34
+ "evaluate",
35
+ "rejected",
36
+ ]);
37
+ const inventoryPath = new URL(
38
+ "../inventory/oxlint-rules.json",
39
+ import.meta.url,
40
+ );
41
+
42
+ describe("oxlint rules inventory", () => {
43
+ /** @type {Record<string, string>} */
44
+ let inventory;
45
+ /** @type {string[]} */
46
+ let oxlintRules;
47
+
48
+ beforeAll(async () => {
49
+ inventory = JSON.parse(await readFile(inventoryPath, "utf8"));
50
+ const rules = await listOxlintRules(import.meta.dirname);
51
+ oxlintRules = rules
52
+ .map(({ name }) => name)
53
+ .filter((name) => plugins.has(name.slice(0, name.indexOf("/"))));
54
+ });
55
+
56
+ it("has a decision for every oxlint rule", () => {
57
+ const oxlintRuleSet = new Set(oxlintRules);
58
+ expect({
59
+ newRules: oxlintRules.filter((name) => !Object.hasOwn(inventory, name)),
60
+ removedRules: Object.keys(inventory).filter(
61
+ (name) => !oxlintRuleSet.has(name),
62
+ ),
63
+ }).toEqual({ newRules: [], removedRules: [] });
64
+ });
65
+
66
+ it("has only known decisions", () => {
67
+ expect(
68
+ Object.entries(inventory).filter(
69
+ ([, decision]) => !decisions.has(decision),
70
+ ),
71
+ ).toEqual([]);
72
+ });
73
+
74
+ it("marks as enabled exactly the rules of oxlint/*.json", () => {
75
+ expect(
76
+ Object.keys(inventory)
77
+ .filter((name) => inventory[name] === "enabled")
78
+ .toSorted(),
79
+ ).toEqual(getEnabledOxlintConfigRules());
80
+ });
81
+ });
@@ -0,0 +1,199 @@
1
+ import { mkdtemp, readFile, rm, writeFile } from "node:fs/promises";
2
+ import { tmpdir } from "node:os";
3
+ import path from "node:path";
4
+ import { afterAll, beforeAll, describe, expect, it } from "vitest";
5
+ import { lintWithOxlint, oxlintConfigsDir } from "./test-utils/oxlint.js";
6
+
7
+ const baseConfigPath = path.join(oxlintConfigsDir, "base.json");
8
+ const typescriptConfigPath = path.join(oxlintConfigsDir, "typescript.json");
9
+ // this repo's config, the options are not in base.json so projects keep
10
+ // eslint-disable comments working
11
+ const rootConfig = JSON.parse(
12
+ await readFile(
13
+ path.resolve(import.meta.dirname, "../../../.oxlintrc.json"),
14
+ "utf8",
15
+ ),
16
+ );
17
+
18
+ /**
19
+ * Lints `source` in a project whose .oxlintrc.json extends base.json, like the
20
+ * one written by pob.
21
+ */
22
+ const lint = async (cwd, source, fileName = "file.js") => {
23
+ await writeFile(path.join(cwd, fileName), source);
24
+ return lintWithOxlint(cwd);
25
+ };
26
+
27
+ const summarize = (diagnostics) =>
28
+ diagnostics.map(({ code, message, labels }) => ({
29
+ line: labels[0].span.line,
30
+ rule: code ?? message,
31
+ }));
32
+
33
+ /**
34
+ * @param {Record<string, unknown>} config
35
+ * @param {string[]} extendsPaths
36
+ */
37
+ const useProject = (config, extendsPaths = [baseConfigPath]) => {
38
+ const project = { cwd: "" };
39
+
40
+ beforeAll(async () => {
41
+ project.cwd = await mkdtemp(path.join(tmpdir(), "pob-oxlint-"));
42
+ await writeFile(
43
+ path.join(project.cwd, ".oxlintrc.json"),
44
+ JSON.stringify({ ...config, extends: extendsPaths }),
45
+ );
46
+ await writeFile(
47
+ path.join(project.cwd, "tsconfig.json"),
48
+ JSON.stringify({ compilerOptions: { strict: true } }),
49
+ );
50
+ });
51
+
52
+ afterAll(async () => {
53
+ if (project.cwd) await rm(project.cwd, { recursive: true, force: true });
54
+ });
55
+
56
+ return project;
57
+ };
58
+
59
+ describe("oxlint/base.json", () => {
60
+ const project = useProject({});
61
+
62
+ it("reports the rule", async () => {
63
+ expect(summarize(await lint(project.cwd, "debugger;\n"))).toEqual([
64
+ { line: 1, rule: "eslint(no-debugger)" },
65
+ ]);
66
+ });
67
+
68
+ it("respects oxlint-disable directives", async () => {
69
+ expect(
70
+ await lint(
71
+ project.cwd,
72
+ "// oxlint-disable-next-line no-debugger\ndebugger;\n",
73
+ ),
74
+ ).toEqual([]);
75
+ });
76
+
77
+ // projects keep their eslint-disable comments when a rule moves to oxlint
78
+ it("respects eslint-disable directives", async () => {
79
+ expect(
80
+ await lint(
81
+ project.cwd,
82
+ "// eslint-disable-next-line no-debugger\ndebugger;\n",
83
+ ),
84
+ ).toEqual([]);
85
+ });
86
+ });
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
+
172
+ describe("root .oxlintrc.json options", () => {
173
+ const project = useProject({ options: rootConfig.options });
174
+
175
+ // with these options, test-lint fixtures prove each oxlint rule fires
176
+ it("ignores eslint-disable directives", async () => {
177
+ expect(
178
+ summarize(
179
+ await lint(
180
+ project.cwd,
181
+ "// eslint-disable-next-line no-debugger\ndebugger;\n",
182
+ ),
183
+ ),
184
+ ).toEqual([{ line: 2, rule: "eslint(no-debugger)" }]);
185
+ });
186
+
187
+ it("reports unused oxlint-disable directives", async () => {
188
+ const diagnostics = await lint(
189
+ project.cwd,
190
+ "// oxlint-disable-next-line no-debugger\nexport const a = 1;\n",
191
+ );
192
+ expect(diagnostics).toHaveLength(1);
193
+ expect(diagnostics[0]).toMatchObject({
194
+ severity: "error",
195
+ message: expect.stringContaining("Unused oxlint-disable directive"),
196
+ labels: [{ span: { line: 1 } }],
197
+ });
198
+ });
199
+ });
@@ -0,0 +1,69 @@
1
+ import { builtinRules } from "eslint/use-at-your-own-risk";
2
+
3
+ /**
4
+ * Rules of eslint core and of the plugins loaded by `configs`.
5
+ *
6
+ * @param {import("eslint").Linter.Config[]} configs
7
+ */
8
+ const getLoadedRules = (configs) => {
9
+ /** @type {Map<string, import("eslint").Rule.RuleModule>} */
10
+ const rules = new Map(builtinRules);
11
+ for (const config of configs) {
12
+ for (const [pluginName, plugin] of Object.entries(config.plugins ?? {})) {
13
+ for (const [ruleName, rule] of Object.entries(plugin.rules ?? {})) {
14
+ rules.set(
15
+ `${pluginName}/${ruleName}`,
16
+ /** @type {import("eslint").Rule.RuleModule} */ (rule),
17
+ );
18
+ }
19
+ }
20
+ }
21
+ return rules;
22
+ };
23
+
24
+ /**
25
+ * Rules configured in `configs`: true when a config enables it, false when
26
+ * configs only turn it off.
27
+ *
28
+ * @param {import("eslint").Linter.Config[]} configs
29
+ */
30
+ const getConfiguredRules = (configs) => {
31
+ /** @type {Map<string, boolean>} */
32
+ const configuredRules = new Map();
33
+ for (const config of configs) {
34
+ for (const [ruleName, ruleEntry] of Object.entries(config.rules ?? {})) {
35
+ const severity = Array.isArray(ruleEntry) ? ruleEntry[0] : ruleEntry;
36
+ const enabled = severity !== "off" && severity !== 0;
37
+ configuredRules.set(ruleName, configuredRules.get(ruleName) || enabled);
38
+ }
39
+ }
40
+ return configuredRules;
41
+ };
42
+
43
+ /**
44
+ * Status of every rule of eslint core and of the plugins loaded by `configs`:
45
+ * `enabled` when a config enables it (for any files), `off` when configs only
46
+ * turn it off, `unset` otherwise. Deprecated rules are listed only when
47
+ * enabled, as `deprecated`.
48
+ *
49
+ * @param {import("eslint").Linter.Config[]} configs
50
+ * @returns {Record<string, "enabled" | "off" | "unset" | "deprecated">}
51
+ */
52
+ export const getEslintRulesStatus = (configs) => {
53
+ const rules = getLoadedRules(configs);
54
+ const configuredRules = getConfiguredRules(configs);
55
+
56
+ /** @type {Record<string, "enabled" | "off" | "unset" | "deprecated">} */
57
+ const status = {};
58
+ for (const ruleName of [...rules.keys()].toSorted()) {
59
+ const enabled = configuredRules.get(ruleName);
60
+ if (rules.get(ruleName)?.meta?.deprecated) {
61
+ if (enabled) status[ruleName] = "deprecated";
62
+ } else if (enabled === undefined) {
63
+ status[ruleName] = "unset";
64
+ } else {
65
+ status[ruleName] = enabled ? "enabled" : "off";
66
+ }
67
+ }
68
+ return status;
69
+ };