@pob/eslint-config 68.3.0 → 68.4.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
@@ -28,7 +28,6 @@ export const applyTs = (options) =>
28
28
  const packageJsonPath = path.resolve("package.json");
29
29
  const isCommonjsPackage =
30
30
  fs.existsSync(packageJsonPath) &&
31
- // oxlint-disable-next-line unicorn-js/prefer-json-parse-buffer
32
31
  JSON.parse(fs.readFileSync(packageJsonPath, "utf8")).type === "commonjs";
33
32
 
34
33
  const moduleFiles = isCommonjsPackage
@@ -1,13 +1,59 @@
1
1
  import { readFileSync, readdirSync } from "node:fs";
2
+ import { readFile } from "node:fs/promises";
2
3
  import path from "node:path";
3
4
  import { pathToFileURL } from "node:url";
4
- import { describe, expect, it } from "vitest";
5
+ import { beforeAll, describe, expect, it } from "vitest";
5
6
  import {
6
7
  getEnabledOxlintConfigRules,
7
8
  oxlintConfigsDir,
8
9
  reactOxlintConfigsDir,
9
10
  } from "./test-utils/oxlint.js";
10
11
 
12
+ /**
13
+ * Native oxlint plugin implementing rules of a JS plugin under the same names,
14
+ * by JS plugin name. oxlint's react plugin also has the react-hooks and React
15
+ * compiler rules.
16
+ *
17
+ * @type {Record<string, string>}
18
+ */
19
+ const nativePluginNames = {
20
+ "eslint-js": "eslint",
21
+ "node-js": "node",
22
+ "react-x": "react",
23
+ "unicorn-js": "unicorn",
24
+ };
25
+
26
+ /**
27
+ * Native oxlint rule of another plugin checking the same thing as a JS plugin
28
+ * rule, by JS plugin rule name. Some JS plugin rules check more (noted).
29
+ *
30
+ * @type {Record<string, string>}
31
+ */
32
+ const nativeRuleNamesOfOtherPlugins = {
33
+ "node-js/no-process-exit": "unicorn/no-process-exit",
34
+ "node-js/prefer-node-protocol": "unicorn/prefer-node-protocol",
35
+ "regexp/prefer-named-capture-group": "eslint/prefer-named-capture-group",
36
+ "regexp/prefer-regexp-exec": "typescript/prefer-regexp-exec",
37
+ "regexp/prefer-regexp-test": "unicorn/prefer-regexp-test",
38
+ "regexp/require-unicode-regexp": "eslint/require-unicode-regexp",
39
+ "unicorn-js/id-match": "eslint/id-match",
40
+ "unicorn-js/logical-assignment-operators":
41
+ "eslint/logical-assignment-operators",
42
+ "unicorn-js/no-loss-of-precision": "eslint/no-loss-of-precision",
43
+ // also reports named usage of default exports
44
+ "unicorn-js/no-named-default": "import/no-named-default",
45
+ "unicorn-js/no-useless-concat": "eslint/no-useless-concat",
46
+ "unicorn-js/operator-assignment": "eslint/operator-assignment",
47
+ // also reports `toSorted()`, without type information
48
+ "unicorn-js/require-array-sort-compare":
49
+ "typescript/require-array-sort-compare",
50
+ };
51
+
52
+ const oxlintRulesInventoryPath = new URL(
53
+ "../inventory/oxlint-rules.json",
54
+ import.meta.url,
55
+ );
56
+
11
57
  /**
12
58
  * eslint plugins run by oxlint as JS plugins (`jsPlugins` of oxlint/*.json),
13
59
  * by plugin name.
@@ -32,31 +78,103 @@ const loadJsPlugins = async () => {
32
78
  return plugins;
33
79
  };
34
80
 
81
+ /*
82
+ * inventory/oxlint-js-plugins-rules.json records the status of every rule of
83
+ * the JS plugins:
84
+ * - enabled: in oxlint/*.json, no native oxlint equivalent
85
+ * - enabled-over-native: in oxlint/*.json, instead of the native oxlint
86
+ * equivalent (decision `js-plugin` in inventory/oxlint-rules.json)
87
+ * - unset-has-native: not enabled, a native oxlint equivalent exists (its
88
+ * decision is in inventory/oxlint-rules.json)
89
+ * - unset: not enabled, no native oxlint equivalent
90
+ * - deprecated: deprecated and enabled (deprecated rules not enabled are not
91
+ * listed)
92
+ * The native equivalent is the rule of the same name (nativePluginNames) or a
93
+ * rule of another plugin (nativeRuleNamesOfOtherPlugins), named after the
94
+ * status: `unset-has-native:eslint/no-loss-of-precision`.
95
+ */
35
96
  describe("oxlint JS plugins rules inventory", () => {
36
- // New rules and newly deprecated ones of the eslint plugins run by oxlint
37
- // show up in the snapshot diff on upgrades.
38
- it("matches the snapshot", async () => {
97
+ /** @type {Record<string, string>} */
98
+ let nativeDecisions;
99
+ /** @type {Map<string, string>} */
100
+ const nativeRuleNames = new Map();
101
+ /** @type {Record<string, string>} */
102
+ const status = {};
103
+
104
+ beforeAll(async () => {
105
+ nativeDecisions = JSON.parse(
106
+ await readFile(oxlintRulesInventoryPath, "utf8"),
107
+ );
39
108
  const enabledRules = new Set(getEnabledOxlintConfigRules());
40
- /** @type {Record<string, "enabled" | "unset" | "deprecated">} */
41
- const status = {};
42
109
  const plugins = await loadJsPlugins();
43
110
  for (const [pluginName, plugin] of [...plugins].toSorted(([a], [b]) =>
44
111
  a.localeCompare(b),
45
112
  )) {
113
+ const nativePluginName = nativePluginNames[pluginName];
46
114
  for (const [ruleName, rule] of Object.entries(
47
115
  plugin.rules ?? {},
48
116
  ).toSorted(([a], [b]) => a.localeCompare(b))) {
49
117
  const fullName = `${pluginName}/${ruleName}`;
50
118
  const enabled = enabledRules.has(fullName);
119
+ const otherPluginNativeRuleName =
120
+ nativeRuleNamesOfOtherPlugins[fullName];
121
+ const nativeRuleName =
122
+ otherPluginNativeRuleName ??
123
+ (nativePluginName && `${nativePluginName}/${ruleName}`);
124
+ const hasNative =
125
+ !!nativeRuleName && Object.hasOwn(nativeDecisions, nativeRuleName);
126
+ if (hasNative) nativeRuleNames.set(fullName, nativeRuleName);
127
+ const nativeSuffix = otherPluginNativeRuleName
128
+ ? `:${otherPluginNativeRuleName}`
129
+ : "";
51
130
  if (/** @type {any} */ (rule).meta?.deprecated) {
52
131
  if (enabled) status[fullName] = "deprecated";
132
+ } else if (enabled) {
133
+ status[fullName] = hasNative
134
+ ? `enabled-over-native${nativeSuffix}`
135
+ : "enabled";
53
136
  } else {
54
- status[fullName] = enabled ? "enabled" : "unset";
137
+ status[fullName] = hasNative
138
+ ? `unset-has-native${nativeSuffix}`
139
+ : "unset";
55
140
  }
56
141
  }
57
142
  }
143
+ });
144
+
145
+ // New rules and newly deprecated ones of the eslint plugins run by oxlint
146
+ // show up in the snapshot diff on upgrades.
147
+ it("matches the snapshot", async () => {
58
148
  await expect(`${JSON.stringify(status, null, 2)}\n`).toMatchFileSnapshot(
59
149
  "../inventory/oxlint-js-plugins-rules.json",
60
150
  );
61
151
  });
152
+
153
+ it("maps JS plugin rules to existing native rules of other plugins", () => {
154
+ expect(
155
+ Object.entries(nativeRuleNamesOfOtherPlugins).filter(
156
+ ([fullName, nativeRuleName]) =>
157
+ !Object.hasOwn(status, fullName) ||
158
+ !Object.hasOwn(nativeDecisions, nativeRuleName),
159
+ ),
160
+ ).toEqual([]);
161
+ });
162
+
163
+ it("enables a JS plugin rule over its native rule exactly when the native decision is js-plugin", () => {
164
+ const nativeRuleNamesOverridden = new Set(
165
+ [...nativeRuleNames]
166
+ .filter(
167
+ ([fullName]) =>
168
+ Object.hasOwn(status, fullName) &&
169
+ (status[fullName].startsWith("enabled-over-native") ||
170
+ status[fullName] === "deprecated"),
171
+ )
172
+ .map(([, nativeRuleName]) => nativeRuleName),
173
+ );
174
+ expect([...nativeRuleNamesOverridden].toSorted()).toEqual(
175
+ Object.keys(nativeDecisions)
176
+ .filter((name) => nativeDecisions[name] === "js-plugin")
177
+ .toSorted(),
178
+ );
179
+ });
62
180
  });
package/oxlint/base.json CHANGED
@@ -982,13 +982,14 @@
982
982
  "regexp/sort-flags": "error",
983
983
  "regexp/strict": "error",
984
984
  "regexp/use-ignore-case": "error",
985
+ "unicorn-js/consistent-json-file-read": "error",
985
986
  "unicorn-js/expiring-todo-comments": [
986
987
  "error",
987
988
  {
988
989
  "terms": ["todo", "fixme", "xxx"],
989
990
  "ignore": [],
990
- "ignoreDates": false,
991
- "ignoreDatesOnPullRequests": true,
991
+ "checkDates": true,
992
+ "checkDatesOnPullRequests": false,
992
993
  "allowWarningComments": true
993
994
  }
994
995
  ],
@@ -999,7 +1000,6 @@
999
1000
  "excludedPackages": ["koa", "sax"]
1000
1001
  }
1001
1002
  ],
1002
- "unicorn-js/prefer-json-parse-buffer": "error",
1003
1003
  "unicorn-js/prefer-switch": [
1004
1004
  "error",
1005
1005
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pob/eslint-config",
3
- "version": "68.3.0",
3
+ "version": "68.4.0",
4
4
  "description": "eslint config files",
5
5
  "keywords": [],
6
6
  "homepage": "https://github.com/christophehurpeau/pob",
@@ -49,13 +49,13 @@
49
49
  },
50
50
  "dependencies": {
51
51
  "@eslint/json": "^2.0.0",
52
- "@pob/eslint-plugin": "67.2.0",
52
+ "@pob/eslint-plugin": "67.3.0",
53
53
  "@typescript-eslint/parser": "8.72.1",
54
54
  "check-package-dependencies": "^13.2.0",
55
55
  "eslint-plugin-import-x": "^4.17.1",
56
56
  "eslint-plugin-n": "^18.5.0",
57
57
  "eslint-plugin-regexp": "^3.3.2",
58
- "eslint-plugin-unicorn": "^64.0.0"
58
+ "eslint-plugin-unicorn": "^79.0.0"
59
59
  },
60
60
  "devDependencies": {
61
61
  "@types/node": "24.19.1",
@@ -63,7 +63,7 @@
63
63
  "eslint-plugin-import-x": "4.17.1",
64
64
  "eslint-plugin-n": "18.5.0",
65
65
  "eslint-plugin-regexp": "3.3.2",
66
- "eslint-plugin-unicorn": "64.0.0",
66
+ "eslint-plugin-unicorn": "79.0.0",
67
67
  "typescript": "npm:@typescript/typescript6@6.0.2"
68
68
  },
69
69
  "peerDependencies": {
@@ -76,7 +76,7 @@
76
76
  }
77
77
  },
78
78
  "engines": {
79
- "node": "^22.18.0 || >=24.14.1"
79
+ "node": "^22.23.4 || ^24.22.1 || >=26.13.0"
80
80
  },
81
81
  "pob": {
82
82
  "typescript": "check-only"