@oxlint/migrate 0.0.4 → 0.15.12
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/README.md +9 -2
- package/dist/bin/oxlint-migrate.mjs +2 -1
- package/dist/package.json.mjs +1 -1
- package/dist/src/cleanup.mjs +18 -48
- package/dist/src/constants.d.ts +1 -0
- package/dist/src/constants.mjs +24 -1
- package/dist/src/env_globals.d.ts +2 -1
- package/dist/src/env_globals.mjs +27 -3
- package/dist/src/generated/rules.d.ts +1 -0
- package/dist/src/generated/rules.mjs +49 -1
- package/dist/src/ignorePatterns.d.ts +1 -1
- package/dist/src/index.mjs +1 -1
- package/dist/src/plugin_rules.test.d.ts +1 -0
- package/dist/src/plugins_rules.d.ts +5 -2
- package/dist/src/plugins_rules.mjs +65 -2
- package/dist/src/types.d.ts +1 -1
- package/package.json +11 -7
package/README.md
CHANGED
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
# oxlint-migrate
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+

|
|
4
|
+
[](https://www.npmjs.com/package/@oxlint/migrate)
|
|
5
|
+
[](https://www.npmjs.com/package/@oxlint/migrate)
|
|
6
|
+
|
|
7
|
+
Generates a `.oxlintrc.json` from a existing eslint flat config.
|
|
4
8
|
|
|
5
9
|
🚧 Still under development
|
|
6
10
|
|
|
7
11
|
## Usage
|
|
8
12
|
|
|
9
|
-
|
|
13
|
+
```shell
|
|
14
|
+
pnpm install @oxlint/migrate
|
|
15
|
+
npx oxlint-migrate <optional-eslint-flat-config-path>
|
|
16
|
+
```
|
|
10
17
|
|
|
11
18
|
When no config file provided, the script searches for the default eslint config filenames in the current directory.
|
|
12
19
|
|
|
@@ -5,6 +5,7 @@ import { existsSync, renameSync, writeFileSync } from "fs";
|
|
|
5
5
|
import main from "../src/index.mjs";
|
|
6
6
|
import path from "path";
|
|
7
7
|
import packageJson from "../package.json.mjs";
|
|
8
|
+
import { pathToFileURL } from "node:url";
|
|
8
9
|
program.name("oxlint-migrate").version(packageJson.version).argument("[eslint-config]", "The path to the eslint v9 config file").action(async (filePath) => {
|
|
9
10
|
let cwd = process.cwd();
|
|
10
11
|
if (filePath === void 0) {
|
|
@@ -18,7 +19,7 @@ program.name("oxlint-migrate").version(packageJson.version).argument("[eslint-co
|
|
|
18
19
|
if (!existsSync(filePath)) {
|
|
19
20
|
program.error(`eslint config file not found: ${filePath}`);
|
|
20
21
|
} else {
|
|
21
|
-
const eslintConfigs = await import(filePath);
|
|
22
|
+
const eslintConfigs = await import(pathToFileURL(filePath).toString());
|
|
22
23
|
const oxlintConfig = "default" in eslintConfigs ? await main(eslintConfigs.default, console.warn) : await main(eslintConfigs, console.warn);
|
|
23
24
|
const oxlintFilePath = path.join(cwd, ".oxlintrc.json");
|
|
24
25
|
if (existsSync(oxlintFilePath)) {
|
package/dist/package.json.mjs
CHANGED
package/dist/src/cleanup.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { removeGlobalsWithAreCoveredByEnv, transformBoolGlobalToString, ES_VERSIONS } from "./env_globals.mjs";
|
|
1
|
+
import { removeGlobalsWithAreCoveredByEnv, transformBoolGlobalToString, ES_VERSIONS, cleanUpUselessOverridesEnv } from "./env_globals.mjs";
|
|
2
|
+
import { replaceTypescriptAliasRules, cleanUpUselessOverridesRules, cleanUpUselessOverridesPlugins } from "./plugins_rules.mjs";
|
|
2
3
|
const isEqualDeep = (a, b) => {
|
|
3
4
|
if (a === b) {
|
|
4
5
|
return true;
|
|
@@ -11,8 +12,6 @@ const isEqualDeep = (a, b) => {
|
|
|
11
12
|
const TS_ESLINT_DEFAULT_OVERRIDE = {
|
|
12
13
|
files: ["**/*.ts", "**/*.tsx", "**/*.mts", "**/*.cts"],
|
|
13
14
|
rules: {
|
|
14
|
-
"constructor-super": "off",
|
|
15
|
-
"getter-return": "off",
|
|
16
15
|
"no-class-assign": "off",
|
|
17
16
|
"no-const-assign": "off",
|
|
18
17
|
"no-dupe-class-members": "off",
|
|
@@ -24,13 +23,12 @@ const TS_ESLINT_DEFAULT_OVERRIDE = {
|
|
|
24
23
|
"no-redeclare": "off",
|
|
25
24
|
"no-setter-return": "off",
|
|
26
25
|
"no-this-before-super": "off",
|
|
27
|
-
"no-undef": "off",
|
|
28
|
-
"no-unreachable": "off",
|
|
29
26
|
"no-unsafe-negation": "off",
|
|
30
27
|
"no-var": "error",
|
|
31
28
|
"prefer-rest-params": "error",
|
|
32
29
|
"prefer-spread": "error"
|
|
33
|
-
}
|
|
30
|
+
},
|
|
31
|
+
plugins: []
|
|
34
32
|
};
|
|
35
33
|
const cleanUpDefaultTypeScriptOverridesForEslint = (config) => {
|
|
36
34
|
if (config.overrides === void 0) {
|
|
@@ -44,47 +42,29 @@ const cleanUpDefaultTypeScriptOverridesForEslint = (config) => {
|
|
|
44
42
|
}
|
|
45
43
|
}
|
|
46
44
|
indexesToDelete.forEach((index) => delete config.overrides[index]);
|
|
45
|
+
config.overrides = config.overrides.filter(
|
|
46
|
+
(overrides) => Object.keys(overrides).length > 0
|
|
47
|
+
);
|
|
47
48
|
if (Object.keys(config.overrides).length === 0) {
|
|
48
49
|
delete config.overrides;
|
|
49
50
|
}
|
|
50
51
|
};
|
|
51
52
|
const cleanUpUselessOverridesEntries = (config) => {
|
|
53
|
+
cleanUpDefaultTypeScriptOverridesForEslint(config);
|
|
54
|
+
cleanUpUselessOverridesRules(config);
|
|
55
|
+
cleanUpUselessOverridesPlugins(config);
|
|
56
|
+
cleanUpUselessOverridesEnv(config);
|
|
52
57
|
if (config.overrides === void 0) {
|
|
53
58
|
return;
|
|
54
59
|
}
|
|
60
|
+
for (const overrideIndex in config.overrides) {
|
|
61
|
+
if (Object.keys(config.overrides[overrideIndex]).length === 1) {
|
|
62
|
+
delete config.overrides[overrideIndex];
|
|
63
|
+
}
|
|
64
|
+
}
|
|
55
65
|
config.overrides = config.overrides.filter(
|
|
56
66
|
(overrides) => Object.keys(overrides).length > 0
|
|
57
67
|
);
|
|
58
|
-
if (config.plugins !== void 0) {
|
|
59
|
-
for (const override of config.overrides) {
|
|
60
|
-
if (override.plugins === void 0) {
|
|
61
|
-
continue;
|
|
62
|
-
}
|
|
63
|
-
override.plugins = override.plugins.filter(
|
|
64
|
-
(overridePlugin) => !config.plugins.includes(overridePlugin)
|
|
65
|
-
);
|
|
66
|
-
if (override.plugins.length === 0) {
|
|
67
|
-
delete override.plugins;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
if (config.env !== void 0) {
|
|
72
|
-
for (const override of config.overrides) {
|
|
73
|
-
if (override.env === void 0) {
|
|
74
|
-
continue;
|
|
75
|
-
}
|
|
76
|
-
for (const [overrideEnv, overrideEnvConfig] of Object.entries(
|
|
77
|
-
override.env
|
|
78
|
-
)) {
|
|
79
|
-
if (overrideEnv in config.env && config.env[overrideEnv] === overrideEnvConfig) {
|
|
80
|
-
delete override.env[overrideEnv];
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
if (Object.keys(override.env).length === 0) {
|
|
84
|
-
delete override.env;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
68
|
if (config.overrides.length === 0) {
|
|
89
69
|
delete config.overrides;
|
|
90
70
|
}
|
|
@@ -92,6 +72,7 @@ const cleanUpUselessOverridesEntries = (config) => {
|
|
|
92
72
|
const cleanUpOxlintConfig = (config) => {
|
|
93
73
|
removeGlobalsWithAreCoveredByEnv(config);
|
|
94
74
|
transformBoolGlobalToString(config);
|
|
75
|
+
replaceTypescriptAliasRules(config);
|
|
95
76
|
if (config.globals !== void 0 && Object.keys(config.globals).length === 0) {
|
|
96
77
|
delete config.globals;
|
|
97
78
|
}
|
|
@@ -108,18 +89,7 @@ const cleanUpOxlintConfig = (config) => {
|
|
|
108
89
|
}
|
|
109
90
|
}
|
|
110
91
|
}
|
|
111
|
-
if (
|
|
112
|
-
delete config.rules;
|
|
113
|
-
}
|
|
114
|
-
if ("files" in config) {
|
|
115
|
-
if (config.plugins !== void 0 && Object.keys(config.plugins).length === 0) {
|
|
116
|
-
delete config.plugins;
|
|
117
|
-
}
|
|
118
|
-
if (Object.keys(config).length === 1) {
|
|
119
|
-
delete config.files;
|
|
120
|
-
}
|
|
121
|
-
} else {
|
|
122
|
-
cleanUpDefaultTypeScriptOverridesForEslint(config);
|
|
92
|
+
if (!("files" in config)) {
|
|
123
93
|
cleanUpUselessOverridesEntries(config);
|
|
124
94
|
}
|
|
125
95
|
};
|
package/dist/src/constants.d.ts
CHANGED
package/dist/src/constants.mjs
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
const rulesPrefixesForPlugins = {
|
|
2
2
|
import: "import",
|
|
3
|
+
"import-x": "import",
|
|
3
4
|
jest: "jest",
|
|
4
5
|
jsdoc: "jsdoc",
|
|
5
6
|
"jsx-a11y": "jsx-a11y",
|
|
6
7
|
"@next/next": "nextjs",
|
|
7
8
|
node: "node",
|
|
9
|
+
n: "node",
|
|
8
10
|
promise: "promise",
|
|
9
11
|
react: "react",
|
|
10
12
|
"react-perf": "react",
|
|
@@ -12,6 +14,27 @@ const rulesPrefixesForPlugins = {
|
|
|
12
14
|
unicorn: "unicorn",
|
|
13
15
|
vitest: "vitest"
|
|
14
16
|
};
|
|
17
|
+
const typescriptRulesExtendEslintRules = [
|
|
18
|
+
"class-methods-use-this",
|
|
19
|
+
"default-param-last",
|
|
20
|
+
"init-declarations",
|
|
21
|
+
"max-params",
|
|
22
|
+
"no-array-constructor",
|
|
23
|
+
"no-dupe-class-members",
|
|
24
|
+
"no-empty-function",
|
|
25
|
+
"no-invalid-this",
|
|
26
|
+
"no-loop-func",
|
|
27
|
+
"no-loss-of-precision",
|
|
28
|
+
"no-magic-numbers",
|
|
29
|
+
"no-redeclare",
|
|
30
|
+
"no-restricted-imports",
|
|
31
|
+
"no-shadow",
|
|
32
|
+
"no-unused-expressions",
|
|
33
|
+
"no-unused-vars",
|
|
34
|
+
"no-use-before-define",
|
|
35
|
+
"no-useless-constructor"
|
|
36
|
+
];
|
|
15
37
|
export {
|
|
16
|
-
rulesPrefixesForPlugins
|
|
38
|
+
rulesPrefixesForPlugins,
|
|
39
|
+
typescriptRulesExtendEslintRules
|
|
17
40
|
};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { OxlintConfigOrOverride, Reporter } from './types.js';
|
|
1
|
+
import { OxlintConfig, OxlintConfigOrOverride, Reporter } from './types.js';
|
|
2
2
|
import { Linter } from 'eslint';
|
|
3
3
|
export declare const ES_VERSIONS: number[];
|
|
4
4
|
export declare const removeGlobalsWithAreCoveredByEnv: (config: OxlintConfigOrOverride) => void;
|
|
5
5
|
export declare const transformBoolGlobalToString: (config: OxlintConfigOrOverride) => void;
|
|
6
6
|
export declare const detectEnvironmentByGlobals: (config: OxlintConfigOrOverride) => void;
|
|
7
7
|
export declare const transformEnvAndGlobals: (eslintConfig: Linter.Config, targetConfig: OxlintConfigOrOverride, reporter?: Reporter) => void;
|
|
8
|
+
export declare const cleanUpUselessOverridesEnv: (config: OxlintConfig) => void;
|
package/dist/src/env_globals.mjs
CHANGED
|
@@ -61,16 +61,19 @@ const removeGlobalsWithAreCoveredByEnv = (config) => {
|
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
|
+
if (Object.keys(config.globals).length === 0) {
|
|
65
|
+
delete config.globals;
|
|
66
|
+
}
|
|
64
67
|
};
|
|
65
68
|
const transformBoolGlobalToString = (config) => {
|
|
66
69
|
if (config.globals === void 0) {
|
|
67
70
|
return;
|
|
68
71
|
}
|
|
69
72
|
for (const [entry, value] of Object.entries(config.globals)) {
|
|
70
|
-
if (value === false) {
|
|
73
|
+
if (value === false || value === "readable") {
|
|
71
74
|
config.globals[entry] = "readonly";
|
|
72
|
-
} else if (value === true) {
|
|
73
|
-
config.globals[entry] = "
|
|
75
|
+
} else if (value === true || value === "writable") {
|
|
76
|
+
config.globals[entry] = "writeable";
|
|
74
77
|
}
|
|
75
78
|
}
|
|
76
79
|
};
|
|
@@ -129,8 +132,29 @@ const transformEnvAndGlobals = (eslintConfig, targetConfig, reporter) => {
|
|
|
129
132
|
}
|
|
130
133
|
}
|
|
131
134
|
};
|
|
135
|
+
const cleanUpUselessOverridesEnv = (config) => {
|
|
136
|
+
if (config.env === void 0 || config.overrides === void 0) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
for (const override of config.overrides) {
|
|
140
|
+
if (override.env === void 0) {
|
|
141
|
+
continue;
|
|
142
|
+
}
|
|
143
|
+
for (const [overrideEnv, overrideEnvConfig] of Object.entries(
|
|
144
|
+
override.env
|
|
145
|
+
)) {
|
|
146
|
+
if (overrideEnv in config.env && config.env[overrideEnv] === overrideEnvConfig) {
|
|
147
|
+
delete override.env[overrideEnv];
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
if (Object.keys(override.env).length === 0) {
|
|
151
|
+
delete override.env;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
};
|
|
132
155
|
export {
|
|
133
156
|
ES_VERSIONS,
|
|
157
|
+
cleanUpUselessOverridesEnv,
|
|
134
158
|
detectEnvironmentByGlobals,
|
|
135
159
|
removeGlobalsWithAreCoveredByEnv,
|
|
136
160
|
transformBoolGlobalToString,
|
|
@@ -6,14 +6,21 @@ const rules = [
|
|
|
6
6
|
"default-param-last",
|
|
7
7
|
"eqeqeq",
|
|
8
8
|
"for-direction",
|
|
9
|
+
"func-style",
|
|
9
10
|
"func-names",
|
|
10
11
|
"getter-return",
|
|
12
|
+
"grouped-accessor-pairs",
|
|
11
13
|
"guard-for-in",
|
|
14
|
+
"init-declarations",
|
|
15
|
+
"max-nested-callbacks",
|
|
16
|
+
"max-lines-per-function",
|
|
12
17
|
"max-classes-per-file",
|
|
18
|
+
"max-depth",
|
|
13
19
|
"max-lines",
|
|
14
20
|
"max-params",
|
|
15
21
|
"new-cap",
|
|
16
22
|
"no-useless-call",
|
|
23
|
+
"no-unneeded-ternary",
|
|
17
24
|
"no-extra-label",
|
|
18
25
|
"no-multi-assign",
|
|
19
26
|
"no-nested-ternary",
|
|
@@ -391,6 +398,7 @@ const rules = [
|
|
|
391
398
|
"unicorn/explicit-length-check",
|
|
392
399
|
"unicorn/filename-case",
|
|
393
400
|
"unicorn/new-for-builtins",
|
|
401
|
+
"unicorn/no-invalid-fetch-options",
|
|
394
402
|
"unicorn/no-abusive-eslint-disable",
|
|
395
403
|
"unicorn/no-anonymous-default-export",
|
|
396
404
|
"unicorn/no-array-for-each",
|
|
@@ -479,6 +487,7 @@ const rules = [
|
|
|
479
487
|
"vitest/prefer-to-be-truthy",
|
|
480
488
|
"vitest/require-local-test-context-for-concurrent-snapshots",
|
|
481
489
|
"@typescript-eslint/default-param-last",
|
|
490
|
+
"@typescript-eslint/init-declarations",
|
|
482
491
|
"@typescript-eslint/max-params",
|
|
483
492
|
"@typescript-eslint/no-restricted-imports",
|
|
484
493
|
"@typescript-eslint/no-array-constructor",
|
|
@@ -491,6 +500,25 @@ const rules = [
|
|
|
491
500
|
"@typescript-eslint/no-unused-expressions",
|
|
492
501
|
"@typescript-eslint/no-unused-vars",
|
|
493
502
|
"@typescript-eslint/no-useless-constructor",
|
|
503
|
+
"import-x/default",
|
|
504
|
+
"import-x/export",
|
|
505
|
+
"import-x/first",
|
|
506
|
+
"import-x/no-named-default",
|
|
507
|
+
"import-x/no-namespace",
|
|
508
|
+
"import-x/max-dependencies",
|
|
509
|
+
"import-x/named",
|
|
510
|
+
"import-x/namespace",
|
|
511
|
+
"import-x/no-amd",
|
|
512
|
+
"import-x/no-commonjs",
|
|
513
|
+
"import-x/no-cycle",
|
|
514
|
+
"import-x/no-default-export",
|
|
515
|
+
"import-x/no-duplicates",
|
|
516
|
+
"import-x/no-dynamic-require",
|
|
517
|
+
"import-x/no-named-as-default",
|
|
518
|
+
"import-x/no-named-as-default-member",
|
|
519
|
+
"import-x/no-self-import",
|
|
520
|
+
"import-x/no-webpack-loader-syntax",
|
|
521
|
+
"import-x/unambiguous",
|
|
494
522
|
"vitest/consistent-test-it",
|
|
495
523
|
"vitest/expect-expect",
|
|
496
524
|
"vitest/max-expects",
|
|
@@ -507,6 +535,7 @@ const rules = [
|
|
|
507
535
|
"vitest/no-interpolation-in-snapshots",
|
|
508
536
|
"vitest/no-restricted-jest-methods",
|
|
509
537
|
"vitest/no-restricted-matchers",
|
|
538
|
+
"vitest/no-standalone-expect",
|
|
510
539
|
"vitest/no-test-prefixes",
|
|
511
540
|
"vitest/no-test-return-statement",
|
|
512
541
|
"vitest/prefer-each",
|
|
@@ -515,6 +544,7 @@ const rules = [
|
|
|
515
544
|
"vitest/prefer-expect-resolves",
|
|
516
545
|
"vitest/prefer-hooks-in-order",
|
|
517
546
|
"vitest/prefer-hooks-on-top",
|
|
547
|
+
"vitest/prefer-lowercase-title",
|
|
518
548
|
"vitest/prefer-mock-promise-shorthand",
|
|
519
549
|
"vitest/prefer-strict-equal",
|
|
520
550
|
"vitest/prefer-to-have-length",
|
|
@@ -524,6 +554,24 @@ const rules = [
|
|
|
524
554
|
"vitest/valid-describe-callback",
|
|
525
555
|
"vitest/valid-expect"
|
|
526
556
|
];
|
|
557
|
+
const nurseryRules = [
|
|
558
|
+
"constructor-super",
|
|
559
|
+
"getter-return",
|
|
560
|
+
"no-restricted-imports",
|
|
561
|
+
"no-undef",
|
|
562
|
+
"no-unreachable",
|
|
563
|
+
"import/export",
|
|
564
|
+
"import/named",
|
|
565
|
+
"oxc/no-map-spread",
|
|
566
|
+
"promise/no-return-in-finally",
|
|
567
|
+
"react-hooks/exhaustive-deps",
|
|
568
|
+
"react/require-render-return",
|
|
569
|
+
"@typescript-eslint/consistent-type-imports",
|
|
570
|
+
"@typescript-eslint/no-restricted-imports",
|
|
571
|
+
"import-x/export",
|
|
572
|
+
"import-x/named"
|
|
573
|
+
];
|
|
527
574
|
export {
|
|
528
|
-
rules as default
|
|
575
|
+
rules as default,
|
|
576
|
+
nurseryRules
|
|
529
577
|
};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { Linter } from 'eslint';
|
|
2
2
|
import { OxlintConfigOrOverride, Reporter } from './types.js';
|
|
3
|
-
export declare const transformIgnorePatterns: (eslintConfig: Linter.Config, targetConfig: OxlintConfigOrOverride, reporter
|
|
3
|
+
export declare const transformIgnorePatterns: (eslintConfig: Linter.Config, targetConfig: OxlintConfigOrOverride, reporter?: Reporter) => void;
|
package/dist/src/index.mjs
CHANGED
|
@@ -46,7 +46,7 @@ const buildConfig = (configs, reporter) => {
|
|
|
46
46
|
cleanUpOxlintConfig(oxlintConfig);
|
|
47
47
|
return oxlintConfig;
|
|
48
48
|
};
|
|
49
|
-
const main = async (configs, reporter
|
|
49
|
+
const main = async (configs, reporter) => {
|
|
50
50
|
const resolved = await Promise.resolve(configs);
|
|
51
51
|
return Array.isArray(resolved) ? buildConfig(resolved, reporter) : buildConfig([resolved], reporter);
|
|
52
52
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import { Linter } from 'eslint';
|
|
2
|
-
import { OxlintConfigOrOverride, Reporter } from './types.js';
|
|
3
|
-
export declare const transformRuleEntry: (eslintConfig: Linter.Config, targetConfig: OxlintConfigOrOverride, reporter
|
|
2
|
+
import { OxlintConfig, OxlintConfigOrOverride, Reporter } from './types.js';
|
|
3
|
+
export declare const transformRuleEntry: (eslintConfig: Linter.Config, targetConfig: OxlintConfigOrOverride, reporter?: Reporter) => void;
|
|
4
4
|
export declare const detectNeededRulesPlugins: (targetConfig: OxlintConfigOrOverride, reporter?: Reporter) => void;
|
|
5
|
+
export declare const cleanUpUselessOverridesPlugins: (config: OxlintConfig) => void;
|
|
6
|
+
export declare const cleanUpUselessOverridesRules: (config: OxlintConfig) => void;
|
|
7
|
+
export declare const replaceTypescriptAliasRules: (config: OxlintConfigOrOverride) => void;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import rules from "./generated/rules.mjs";
|
|
2
|
-
import { rulesPrefixesForPlugins } from "./constants.mjs";
|
|
1
|
+
import rules, { nurseryRules } from "./generated/rules.mjs";
|
|
2
|
+
import { rulesPrefixesForPlugins, typescriptRulesExtendEslintRules } from "./constants.mjs";
|
|
3
3
|
const isValueInSet = (value, validSet) => validSet.includes(value) || Array.isArray(value) && validSet.includes(value[0]);
|
|
4
4
|
const isActiveValue = (value) => isValueInSet(value, ["error", "warn", 1, 2]);
|
|
5
5
|
const transformRuleEntry = (eslintConfig, targetConfig, reporter) => {
|
|
@@ -11,6 +11,10 @@ const transformRuleEntry = (eslintConfig, targetConfig, reporter) => {
|
|
|
11
11
|
}
|
|
12
12
|
for (const [rule, config] of Object.entries(eslintConfig.rules)) {
|
|
13
13
|
if (rules.includes(rule)) {
|
|
14
|
+
if (nurseryRules.includes(rule)) {
|
|
15
|
+
reporter !== void 0 && reporter(`unsupported rule, but in development: ${rule}`);
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
14
18
|
targetConfig.rules[rule] = config;
|
|
15
19
|
} else {
|
|
16
20
|
if (isActiveValue(config)) {
|
|
@@ -44,7 +48,66 @@ const detectNeededRulesPlugins = (targetConfig, reporter) => {
|
|
|
44
48
|
}
|
|
45
49
|
}
|
|
46
50
|
};
|
|
51
|
+
const cleanUpUselessOverridesPlugins = (config) => {
|
|
52
|
+
if (config.overrides === void 0) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
if (config.plugins !== void 0) {
|
|
56
|
+
for (const override of config.overrides) {
|
|
57
|
+
if (override.plugins === void 0) {
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
override.plugins = override.plugins.filter(
|
|
61
|
+
(overridePlugin) => !config.plugins.includes(overridePlugin)
|
|
62
|
+
);
|
|
63
|
+
if (override.plugins.length === 0) {
|
|
64
|
+
delete override.plugins;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
const cleanUpUselessOverridesRules = (config) => {
|
|
70
|
+
if (config.rules === void 0 || config.overrides === void 0) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
for (const override of config.overrides) {
|
|
74
|
+
if (override.rules === void 0) {
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
for (const [rule, settings] of Object.entries(override.rules)) {
|
|
78
|
+
if (config.rules[rule] === settings) {
|
|
79
|
+
delete override.rules[rule];
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (Object.keys(override.rules).length === 0) {
|
|
83
|
+
delete override.rules;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
const replaceTypescriptAliasRules = (config) => {
|
|
88
|
+
if (config.rules === void 0) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
for (const rule of Object.keys(config.rules)) {
|
|
92
|
+
const prefix = "@typescript-eslint/";
|
|
93
|
+
if (!rule.startsWith(prefix)) {
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
const eslintRule = rule.slice(prefix.length);
|
|
97
|
+
if (!typescriptRulesExtendEslintRules.includes(eslintRule)) {
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
config.rules[eslintRule] = config.rules[rule];
|
|
101
|
+
delete config.rules[rule];
|
|
102
|
+
}
|
|
103
|
+
if (Object.keys(config.rules).length === 0) {
|
|
104
|
+
delete config.rules;
|
|
105
|
+
}
|
|
106
|
+
};
|
|
47
107
|
export {
|
|
108
|
+
cleanUpUselessOverridesPlugins,
|
|
109
|
+
cleanUpUselessOverridesRules,
|
|
48
110
|
detectNeededRulesPlugins,
|
|
111
|
+
replaceTypescriptAliasRules,
|
|
49
112
|
transformRuleEntry
|
|
50
113
|
};
|
package/dist/src/types.d.ts
CHANGED
|
@@ -21,5 +21,5 @@ export type OxlintConfig = {
|
|
|
21
21
|
ignorePatterns?: OxlintConfigIgnorePatterns;
|
|
22
22
|
};
|
|
23
23
|
export type OxlintConfigOrOverride = OxlintConfig | OxlintConfigOverride;
|
|
24
|
-
export type Reporter = (
|
|
24
|
+
export type Reporter = (warning: string) => void;
|
|
25
25
|
export {};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oxlint/migrate",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Generates a `.oxlintrc.json` from a existing eslint
|
|
3
|
+
"version": "0.15.12",
|
|
4
|
+
"description": "Generates a `.oxlintrc.json` from a existing eslint flat config",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
7
7
|
"oxlint-migrate": "./dist/bin/oxlint-migrate.mjs"
|
|
@@ -33,21 +33,25 @@
|
|
|
33
33
|
"license": "MIT",
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@antfu/eslint-config": "^4.2.0",
|
|
36
|
-
"@
|
|
36
|
+
"@eslint/js": "^9.20.0",
|
|
37
|
+
"@logux/eslint-config": "^55.0.0",
|
|
37
38
|
"@oxc-node/core": "^0.0.19",
|
|
38
|
-
"@stylistic/eslint-plugin-ts": "^
|
|
39
|
+
"@stylistic/eslint-plugin-ts": "^4.0.0",
|
|
39
40
|
"@types/eslint-config-prettier": "^6.11.3",
|
|
40
41
|
"@types/node": "^22.13.4",
|
|
41
42
|
"@vitest/coverage-v8": "^3.0.5",
|
|
42
43
|
"eslint": "^9.20.1",
|
|
43
44
|
"eslint-config-prettier": "^10.0.1",
|
|
44
45
|
"eslint-plugin-header": "^3.1.1",
|
|
46
|
+
"eslint-plugin-import-x": "^4.6.1",
|
|
47
|
+
"eslint-plugin-jsdoc": "^50.6.3",
|
|
45
48
|
"eslint-plugin-local": "^6.0.0",
|
|
46
49
|
"eslint-plugin-oxlint": "^0.15.10",
|
|
47
50
|
"eslint-plugin-regexp": "^2.7.0",
|
|
51
|
+
"eslint-plugin-unicorn": "^57.0.0",
|
|
48
52
|
"husky": "^9.1.7",
|
|
49
53
|
"lint-staged": "^15.4.3",
|
|
50
|
-
"oxlint": "^0.15.
|
|
54
|
+
"oxlint": "^0.15.12",
|
|
51
55
|
"prettier": "^3.5.1",
|
|
52
56
|
"typescript": "^5.7.3",
|
|
53
57
|
"typescript-eslint": "^8.24.0",
|
|
@@ -60,7 +64,7 @@
|
|
|
60
64
|
},
|
|
61
65
|
"dependencies": {
|
|
62
66
|
"commander": "^13.1.0",
|
|
63
|
-
"globals": "^
|
|
67
|
+
"globals": "^16.0.0"
|
|
64
68
|
},
|
|
65
|
-
"packageManager": "pnpm@
|
|
69
|
+
"packageManager": "pnpm@10.4.1"
|
|
66
70
|
}
|