Skip to content

Commit 8849227

Browse files
committed
feat: add oxlint migration scripts
1 parent b1ca32b commit 8849227

File tree

1 file changed

+83
-0
lines changed

1 file changed

+83
-0
lines changed

actions/unjs/oxlint.ts

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import { defineAction } from "codeup";
2+
3+
// https://eslint.org/docs/latest/use/configure/configuration-files
4+
const ESLINT_CONFIG_FILES = [
5+
"eslint.config.js",
6+
"eslint.config.mjs",
7+
"eslint.config.cjs",
8+
"eslint.config.ts",
9+
"eslint.config.mts",
10+
"eslint.config.cts",
11+
".eslintrc",
12+
".eslintrc.js",
13+
".eslintrc.cjs",
14+
".eslintrc.yaml",
15+
".eslintrc.yml",
16+
".eslintrc.json",
17+
".eslintignore",
18+
];
19+
20+
export default defineAction({
21+
meta: {
22+
name: "oxlint",
23+
description: "Switch from ESLint to oxlint",
24+
date: "2026-01-29",
25+
},
26+
async filter({ utils }) {
27+
// Only apply if an eslint config exists
28+
return (
29+
(await utils.existsWithAnyExt("eslint.config")) ||
30+
(await utils.existsWithAnyExt(".eslintrc"))
31+
);
32+
},
33+
async apply({ utils }) {
34+
// Remove eslint from devDependencies
35+
const packageJson = await utils.readPackageJSON();
36+
if (packageJson?.devDependencies?.eslint) {
37+
await utils.removeDependency("eslint");
38+
}
39+
40+
// Remove all eslint config files
41+
for (const file of ESLINT_CONFIG_FILES) {
42+
await utils.remove(file);
43+
}
44+
45+
// Create oxlint.json config
46+
await utils.write(
47+
"oxlint.json",
48+
JSON.stringify(
49+
{
50+
$schema: "https://unpkg.com/oxlint/configuration_schema.json",
51+
plugins: ["unicorn", "typescript", "oxc"],
52+
},
53+
null,
54+
2,
55+
),
56+
{ skipIfExists: true },
57+
);
58+
59+
// Install oxlint as dev dependency
60+
await utils.addDevDependency("oxlint");
61+
62+
// Update package.json scripts to use oxlint instead of eslint
63+
await utils.updatePackageJSON((pkg) => {
64+
if (!pkg.scripts) {
65+
return;
66+
}
67+
for (const name of ["lint", "lint:fix", "format"]) {
68+
if (pkg.scripts[name]) {
69+
// Replace eslint --fix with oxlint --fix
70+
pkg.scripts[name] = pkg.scripts[name].replace(
71+
/eslint\s+--fix\b/g,
72+
"oxlint --fix",
73+
);
74+
// Replace eslint with oxlint (for non --fix cases)
75+
pkg.scripts[name] = pkg.scripts[name].replace(
76+
/eslint(?!\s+--fix)\b/g,
77+
"oxlint",
78+
);
79+
}
80+
}
81+
});
82+
},
83+
});

0 commit comments

Comments
 (0)