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