@pob/eslint-config 68.3.0 → 68.5.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 +1 -2
- package/lib/index.test.js +14 -0
- package/lib/overrides/test.js +4 -0
- package/lib/oxlint-js-plugins-rules.test.js +129 -7
- package/lib/test-utils/oxlint.js +23 -5
- package/oxlint/base.json +3 -3
- package/package.json +13 -13
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
|
|
@@ -47,7 +46,7 @@ const scriptsCommonjsFiles = isCommonjsPackage
|
|
|
47
46
|
|
|
48
47
|
const testFiles = [
|
|
49
48
|
`**/*.{test,test-e2e,spec}.{js,cjs,mjs,${tsExtensions.slice(1, -1)}}`,
|
|
50
|
-
`**/{__tests__,__mocks__}/**/*.{js,cjs,mjs,${tsExtensions.slice(1, -1)}}`,
|
|
49
|
+
`**/{__tests__,__mocks__,test,tests}/**/*.{js,cjs,mjs,${tsExtensions.slice(1, -1)}}`,
|
|
51
50
|
];
|
|
52
51
|
|
|
53
52
|
/** @type {import("eslint").Linter.Config[]} */
|
package/lib/index.test.js
CHANGED
|
@@ -71,6 +71,20 @@ describe("configs.node", () => {
|
|
|
71
71
|
);
|
|
72
72
|
expect(config.languageOptions.parserOptions.project).toBeUndefined();
|
|
73
73
|
});
|
|
74
|
+
|
|
75
|
+
it.each([
|
|
76
|
+
["src/file.test.ts", ["vitest"]],
|
|
77
|
+
["src/tests/helpers.ts", ["vitest"]],
|
|
78
|
+
["src/git/test/fixture.ts", ["vitest"]],
|
|
79
|
+
["src/file.ts", undefined],
|
|
80
|
+
])("resolves vitest as a core module in %s", async (filePath, expected) => {
|
|
81
|
+
const config = await new ESLint({
|
|
82
|
+
cwd: rootDir,
|
|
83
|
+
overrideConfigFile: true,
|
|
84
|
+
overrideConfig: configs.node,
|
|
85
|
+
}).calculateConfigForFile(path.join(rootDir, filePath));
|
|
86
|
+
expect(config.settings["import-x/core-modules"]).toEqual(expected);
|
|
87
|
+
});
|
|
74
88
|
});
|
|
75
89
|
|
|
76
90
|
describe("configs.baseModule", () => {
|
package/lib/overrides/test.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
/** @type {import("eslint").Linter.Config} */
|
|
2
2
|
export default {
|
|
3
3
|
name: "@pob/eslint-config/test",
|
|
4
|
+
// in a monorepo, vitest is a dependency of the root, not of each package
|
|
5
|
+
settings: {
|
|
6
|
+
"import-x/core-modules": ["vitest"],
|
|
7
|
+
},
|
|
4
8
|
rules: {
|
|
5
9
|
// allow dev dependencies
|
|
6
10
|
"import-x/no-extraneous-dependencies": ["error", { devDependencies: true }],
|
|
@@ -1,13 +1,60 @@
|
|
|
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,
|
|
8
|
+
getOffOxlintConfigRules,
|
|
7
9
|
oxlintConfigsDir,
|
|
8
10
|
reactOxlintConfigsDir,
|
|
9
11
|
} from "./test-utils/oxlint.js";
|
|
10
12
|
|
|
13
|
+
/**
|
|
14
|
+
* Native oxlint plugin implementing rules of a JS plugin under the same names,
|
|
15
|
+
* by JS plugin name. oxlint's react plugin also has the react-hooks and React
|
|
16
|
+
* compiler rules.
|
|
17
|
+
*
|
|
18
|
+
* @type {Record<string, string>}
|
|
19
|
+
*/
|
|
20
|
+
const nativePluginNames = {
|
|
21
|
+
"eslint-js": "eslint",
|
|
22
|
+
"node-js": "node",
|
|
23
|
+
"react-x": "react",
|
|
24
|
+
"unicorn-js": "unicorn",
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Native oxlint rule of another plugin checking the same thing as a JS plugin
|
|
29
|
+
* rule, by JS plugin rule name. Some JS plugin rules check more (noted).
|
|
30
|
+
*
|
|
31
|
+
* @type {Record<string, string>}
|
|
32
|
+
*/
|
|
33
|
+
const nativeRuleNamesOfOtherPlugins = {
|
|
34
|
+
"node-js/no-process-exit": "unicorn/no-process-exit",
|
|
35
|
+
"node-js/prefer-node-protocol": "unicorn/prefer-node-protocol",
|
|
36
|
+
"regexp/prefer-named-capture-group": "eslint/prefer-named-capture-group",
|
|
37
|
+
"regexp/prefer-regexp-exec": "typescript/prefer-regexp-exec",
|
|
38
|
+
"regexp/prefer-regexp-test": "unicorn/prefer-regexp-test",
|
|
39
|
+
"regexp/require-unicode-regexp": "eslint/require-unicode-regexp",
|
|
40
|
+
"unicorn-js/id-match": "eslint/id-match",
|
|
41
|
+
"unicorn-js/logical-assignment-operators":
|
|
42
|
+
"eslint/logical-assignment-operators",
|
|
43
|
+
"unicorn-js/no-loss-of-precision": "eslint/no-loss-of-precision",
|
|
44
|
+
// also reports named usage of default exports
|
|
45
|
+
"unicorn-js/no-named-default": "import/no-named-default",
|
|
46
|
+
"unicorn-js/no-useless-concat": "eslint/no-useless-concat",
|
|
47
|
+
"unicorn-js/operator-assignment": "eslint/operator-assignment",
|
|
48
|
+
// also reports `toSorted()`, without type information
|
|
49
|
+
"unicorn-js/require-array-sort-compare":
|
|
50
|
+
"typescript/require-array-sort-compare",
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const oxlintRulesInventoryPath = new URL(
|
|
54
|
+
"../inventory/oxlint-rules.json",
|
|
55
|
+
import.meta.url,
|
|
56
|
+
);
|
|
57
|
+
|
|
11
58
|
/**
|
|
12
59
|
* eslint plugins run by oxlint as JS plugins (`jsPlugins` of oxlint/*.json),
|
|
13
60
|
* by plugin name.
|
|
@@ -32,31 +79,106 @@ const loadJsPlugins = async () => {
|
|
|
32
79
|
return plugins;
|
|
33
80
|
};
|
|
34
81
|
|
|
82
|
+
/*
|
|
83
|
+
* inventory/oxlint-js-plugins-rules.json records the status of every rule of
|
|
84
|
+
* the JS plugins, derived from oxlint/*.json:
|
|
85
|
+
* - enabled: enabled, no native oxlint equivalent
|
|
86
|
+
* - enabled:over-native: enabled instead of the native oxlint equivalent
|
|
87
|
+
* (decision `js-plugin` in inventory/oxlint-rules.json)
|
|
88
|
+
* - native: not enabled, a native oxlint equivalent exists (its decision is in
|
|
89
|
+
* inventory/oxlint-rules.json)
|
|
90
|
+
* - rejected: explicitly "off", no native oxlint equivalent
|
|
91
|
+
* - evaluate: not in oxlint/*.json, no native oxlint equivalent (new rules of
|
|
92
|
+
* plugin upgrades)
|
|
93
|
+
* - deprecated: deprecated and enabled (deprecated rules not enabled are not
|
|
94
|
+
* listed)
|
|
95
|
+
* The native equivalent is the rule of the same name (nativePluginNames) or a
|
|
96
|
+
* rule of another plugin (nativeRuleNamesOfOtherPlugins), named after the
|
|
97
|
+
* status: `native:eslint/no-loss-of-precision`.
|
|
98
|
+
*/
|
|
35
99
|
describe("oxlint JS plugins rules inventory", () => {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
100
|
+
/** @type {Record<string, string>} */
|
|
101
|
+
let nativeDecisions;
|
|
102
|
+
/** @type {Map<string, string>} */
|
|
103
|
+
const nativeRuleNames = new Map();
|
|
104
|
+
/** @type {Record<string, string>} */
|
|
105
|
+
const status = {};
|
|
106
|
+
|
|
107
|
+
beforeAll(async () => {
|
|
108
|
+
nativeDecisions = JSON.parse(
|
|
109
|
+
await readFile(oxlintRulesInventoryPath, "utf8"),
|
|
110
|
+
);
|
|
39
111
|
const enabledRules = new Set(getEnabledOxlintConfigRules());
|
|
40
|
-
|
|
41
|
-
const status = {};
|
|
112
|
+
const offRules = new Set(getOffOxlintConfigRules());
|
|
42
113
|
const plugins = await loadJsPlugins();
|
|
43
114
|
for (const [pluginName, plugin] of [...plugins].toSorted(([a], [b]) =>
|
|
44
115
|
a.localeCompare(b),
|
|
45
116
|
)) {
|
|
117
|
+
const nativePluginName = nativePluginNames[pluginName];
|
|
46
118
|
for (const [ruleName, rule] of Object.entries(
|
|
47
119
|
plugin.rules ?? {},
|
|
48
120
|
).toSorted(([a], [b]) => a.localeCompare(b))) {
|
|
49
121
|
const fullName = `${pluginName}/${ruleName}`;
|
|
50
122
|
const enabled = enabledRules.has(fullName);
|
|
123
|
+
const otherPluginNativeRuleName =
|
|
124
|
+
nativeRuleNamesOfOtherPlugins[fullName];
|
|
125
|
+
const nativeRuleName =
|
|
126
|
+
otherPluginNativeRuleName ??
|
|
127
|
+
(nativePluginName && `${nativePluginName}/${ruleName}`);
|
|
128
|
+
const hasNative =
|
|
129
|
+
!!nativeRuleName && Object.hasOwn(nativeDecisions, nativeRuleName);
|
|
130
|
+
if (hasNative) nativeRuleNames.set(fullName, nativeRuleName);
|
|
131
|
+
const nativeSuffix = otherPluginNativeRuleName
|
|
132
|
+
? `:${otherPluginNativeRuleName}`
|
|
133
|
+
: "";
|
|
51
134
|
if (/** @type {any} */ (rule).meta?.deprecated) {
|
|
52
135
|
if (enabled) status[fullName] = "deprecated";
|
|
136
|
+
} else if (enabled) {
|
|
137
|
+
status[fullName] = hasNative
|
|
138
|
+
? `enabled:over-native${nativeSuffix}`
|
|
139
|
+
: "enabled";
|
|
140
|
+
} else if (hasNative) {
|
|
141
|
+
status[fullName] = `native${nativeSuffix}`;
|
|
53
142
|
} else {
|
|
54
|
-
status[fullName] =
|
|
143
|
+
status[fullName] = offRules.has(fullName) ? "rejected" : "evaluate";
|
|
55
144
|
}
|
|
56
145
|
}
|
|
57
146
|
}
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
// New rules and newly deprecated ones of the eslint plugins run by oxlint
|
|
150
|
+
// show up in the snapshot diff on upgrades.
|
|
151
|
+
it("matches the snapshot", async () => {
|
|
58
152
|
await expect(`${JSON.stringify(status, null, 2)}\n`).toMatchFileSnapshot(
|
|
59
153
|
"../inventory/oxlint-js-plugins-rules.json",
|
|
60
154
|
);
|
|
61
155
|
});
|
|
156
|
+
|
|
157
|
+
it("maps JS plugin rules to existing native rules of other plugins", () => {
|
|
158
|
+
expect(
|
|
159
|
+
Object.entries(nativeRuleNamesOfOtherPlugins).filter(
|
|
160
|
+
([fullName, nativeRuleName]) =>
|
|
161
|
+
!Object.hasOwn(status, fullName) ||
|
|
162
|
+
!Object.hasOwn(nativeDecisions, nativeRuleName),
|
|
163
|
+
),
|
|
164
|
+
).toEqual([]);
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it("enables a JS plugin rule over its native rule exactly when the native decision is js-plugin", () => {
|
|
168
|
+
const nativeRuleNamesOverridden = new Set(
|
|
169
|
+
[...nativeRuleNames]
|
|
170
|
+
.filter(
|
|
171
|
+
([fullName]) =>
|
|
172
|
+
Object.hasOwn(status, fullName) &&
|
|
173
|
+
(status[fullName].startsWith("enabled:over-native") ||
|
|
174
|
+
status[fullName] === "deprecated"),
|
|
175
|
+
)
|
|
176
|
+
.map(([, nativeRuleName]) => nativeRuleName),
|
|
177
|
+
);
|
|
178
|
+
expect([...nativeRuleNamesOverridden].toSorted()).toEqual(
|
|
179
|
+
Object.keys(nativeDecisions)
|
|
180
|
+
.filter((name) => nativeDecisions[name] === "js-plugin")
|
|
181
|
+
.toSorted(),
|
|
182
|
+
);
|
|
183
|
+
});
|
|
62
184
|
});
|
package/lib/test-utils/oxlint.js
CHANGED
|
@@ -99,13 +99,14 @@ const isRuleEnabled = (ruleEntry) => {
|
|
|
99
99
|
};
|
|
100
100
|
|
|
101
101
|
/**
|
|
102
|
-
* Rules
|
|
103
|
-
* @pob/eslint-config-typescript-react (including `overrides`)
|
|
104
|
-
* `plugin/rule`.
|
|
102
|
+
* Rules of `oxlint/*.json` of this package and of
|
|
103
|
+
* @pob/eslint-config-typescript-react (including `overrides`) whose entry
|
|
104
|
+
* matches `filter`, as `plugin/rule`.
|
|
105
105
|
*
|
|
106
|
+
* @param {(ruleEntry: unknown) => boolean} filter
|
|
106
107
|
* @returns {string[]}
|
|
107
108
|
*/
|
|
108
|
-
|
|
109
|
+
const getOxlintConfigRules = (filter) => {
|
|
109
110
|
const ruleNames = new Set();
|
|
110
111
|
const configPaths = [oxlintConfigsDir, reactOxlintConfigsDir].flatMap((dir) =>
|
|
111
112
|
readdirSync(dir)
|
|
@@ -120,7 +121,7 @@ export const getEnabledOxlintConfigRules = () => {
|
|
|
120
121
|
...(config.overrides ?? []).map((override) => override.rules),
|
|
121
122
|
]) {
|
|
122
123
|
for (const [ruleName, ruleEntry] of Object.entries(rules ?? {})) {
|
|
123
|
-
if (
|
|
124
|
+
if (filter(ruleEntry)) {
|
|
124
125
|
ruleNames.add(toCanonicalOxlintRuleName(ruleName));
|
|
125
126
|
}
|
|
126
127
|
}
|
|
@@ -128,3 +129,20 @@ export const getEnabledOxlintConfigRules = () => {
|
|
|
128
129
|
}
|
|
129
130
|
return [...ruleNames].toSorted();
|
|
130
131
|
};
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* Rules enabled in `oxlint/*.json`, see getOxlintConfigRules.
|
|
135
|
+
*
|
|
136
|
+
* @returns {string[]}
|
|
137
|
+
*/
|
|
138
|
+
export const getEnabledOxlintConfigRules = () =>
|
|
139
|
+
getOxlintConfigRules(isRuleEnabled);
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Rules turned off in `oxlint/*.json` (enabled in another file or override
|
|
143
|
+
* included), see getOxlintConfigRules.
|
|
144
|
+
*
|
|
145
|
+
* @returns {string[]}
|
|
146
|
+
*/
|
|
147
|
+
export const getOffOxlintConfigRules = () =>
|
|
148
|
+
getOxlintConfigRules((ruleEntry) => !isRuleEnabled(ruleEntry));
|
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
|
-
"
|
|
991
|
-
"
|
|
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
|
+
"version": "68.5.0",
|
|
4
4
|
"description": "eslint config files",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"homepage": "https://github.com/christophehurpeau/pob",
|
|
@@ -48,26 +48,26 @@
|
|
|
48
48
|
"access": "public"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@eslint/json": "^2.
|
|
52
|
-
"@pob/eslint-plugin": "67.
|
|
53
|
-
"@typescript-eslint/parser": "8.72.
|
|
54
|
-
"check-package-dependencies": "^13.
|
|
55
|
-
"eslint-plugin-import-x": "^4.
|
|
51
|
+
"@eslint/json": "^2.1.1",
|
|
52
|
+
"@pob/eslint-plugin": "67.3.1",
|
|
53
|
+
"@typescript-eslint/parser": "8.72.2",
|
|
54
|
+
"check-package-dependencies": "^13.3.0",
|
|
55
|
+
"eslint-plugin-import-x": "^4.18.1",
|
|
56
56
|
"eslint-plugin-n": "^18.5.0",
|
|
57
|
-
"eslint-plugin-regexp": "^3.3.
|
|
58
|
-
"eslint-plugin-unicorn": "^
|
|
57
|
+
"eslint-plugin-regexp": "^3.3.3",
|
|
58
|
+
"eslint-plugin-unicorn": "^79.0.0"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
61
|
"@types/node": "24.19.1",
|
|
62
62
|
"eslint": "10.14.0",
|
|
63
|
-
"eslint-plugin-import-x": "4.
|
|
63
|
+
"eslint-plugin-import-x": "4.18.1",
|
|
64
64
|
"eslint-plugin-n": "18.5.0",
|
|
65
|
-
"eslint-plugin-regexp": "3.3.
|
|
66
|
-
"eslint-plugin-unicorn": "
|
|
65
|
+
"eslint-plugin-regexp": "3.3.3",
|
|
66
|
+
"eslint-plugin-unicorn": "79.0.0",
|
|
67
67
|
"typescript": "npm:@typescript/typescript6@6.0.2"
|
|
68
68
|
},
|
|
69
69
|
"peerDependencies": {
|
|
70
|
-
"eslint": "^10.
|
|
70
|
+
"eslint": "^10.14.0",
|
|
71
71
|
"typescript": ">=5.0.0 <8.0.0"
|
|
72
72
|
},
|
|
73
73
|
"peerDependenciesMeta": {
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
}
|
|
77
77
|
},
|
|
78
78
|
"engines": {
|
|
79
|
-
"node": "^22.
|
|
79
|
+
"node": "^22.23.4 || ^24.22.1 || >=26.13.0"
|
|
80
80
|
},
|
|
81
81
|
"pob": {
|
|
82
82
|
"typescript": "check-only"
|