Skip to content

Commit e3c79b9

Browse files
connorsheafengmk2
andauthored
fix: support JSONC format in oxlintrc/oxfmtrc migration (#1195)
## Summary - Add `.oxlintrc.jsonc` and `.oxfmtrc.jsonc` as valid config file names in the migrator detector - Use `jsonc-parser` instead of `JSON.parse` so oxlint/oxfmt config files with JSONC syntax (comments, trailing commas) are parsed correctly during migration — this also fixes `.oxlintrc.json` files that use JSONC syntax, since oxlint supports JSONC regardless of extension - Add snap test with JSONC features (comments, trailing commas) to verify the migration works Closes #1193 Ref: oxc-project/oxc#19870 --------- Signed-off-by: Connor Shea <connor.james.shea@gmail.com> Co-authored-by: MK (fengmk2) <fengmk2@gmail.com>
1 parent 25741aa commit e3c79b9

11 files changed

Lines changed: 153 additions & 2 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"$schema": "./node_modules/oxlint/configuration_schema.json",
3+
"categories": {
4+
"correctness": "error"
5+
},
6+
"rules": {
7+
// this is a comment
8+
"no-console": "error"
9+
},
10+
"globals": {},
11+
"ignorePatterns": []
12+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"devDependencies": {
3+
"oxlint": "1"
4+
}
5+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
> vp migrate --no-interactive 2>&1 # migration should handle .oxlintrc.json with JSONC comments
2+
VITE+ - The Unified Toolchain for the Web
3+
4+
◇ Migrated . to Vite+<repeat>
5+
• Node <semver> pnpm <semver>
6+
• 3 config updates applied
7+
8+
> cat vite.config.ts # check vite.config.ts
9+
import { defineConfig } from 'vite-plus';
10+
11+
export default defineConfig({
12+
staged: {
13+
"*": "vp check --fix"
14+
},
15+
fmt: {},
16+
lint: {
17+
"categories": {
18+
"correctness": "error"
19+
},
20+
"rules": {
21+
"no-console": "error"
22+
},
23+
"globals": {},
24+
"ignorePatterns": [],
25+
"options": {
26+
"typeAware": true,
27+
"typeCheck": true
28+
}
29+
},
30+
});
31+
32+
> test ! -f .oxlintrc.json # check .oxlintrc.json is removed
33+
> cat package.json # check package.json
34+
{
35+
"devDependencies": {
36+
"vite-plus": "latest"
37+
},
38+
"pnpm": {
39+
"overrides": {
40+
"vite": "npm:@voidzero-dev/vite-plus-core@latest",
41+
"vitest": "npm:@voidzero-dev/vite-plus-test@latest"
42+
}
43+
},
44+
"packageManager": "pnpm@<semver>",
45+
"scripts": {
46+
"prepare": "vp config"
47+
}
48+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"commands": [
3+
"vp migrate --no-interactive 2>&1 # migration should handle .oxlintrc.json with JSONC comments",
4+
"cat vite.config.ts # check vite.config.ts",
5+
"test ! -f .oxlintrc.json # check .oxlintrc.json is removed",
6+
"cat package.json # check package.json"
7+
]
8+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"printWidth": 100,
3+
"tabWidth": 2,
4+
"semi": true,
5+
"singleQuote": true,
6+
"trailingComma": "es5",
7+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"rules": {
3+
// this is a comment
4+
"no-unused-vars": "error",
5+
},
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"devDependencies": {
3+
"oxfmt": "1",
4+
"oxlint": "1"
5+
}
6+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
> vp migrate --no-interactive 2>&1 # migration should detect .oxlintrc.jsonc and .oxfmtrc.jsonc
2+
VITE+ - The Unified Toolchain for the Web
3+
4+
◇ Migrated . to Vite+<repeat>
5+
• Node <semver> pnpm <semver>
6+
• 4 config updates applied
7+
8+
> cat vite.config.ts # check vite.config.ts
9+
import { defineConfig } from 'vite-plus';
10+
11+
export default defineConfig({
12+
staged: {
13+
"*": "vp check --fix"
14+
},
15+
fmt: {
16+
"printWidth": 100,
17+
"tabWidth": 2,
18+
"semi": true,
19+
"singleQuote": true,
20+
"trailingComma": "es5",
21+
},
22+
lint: {
23+
"rules": {
24+
"no-unused-vars": "error"
25+
},
26+
"options": {
27+
"typeAware": true,
28+
"typeCheck": true
29+
}
30+
},
31+
});
32+
33+
> test ! -f .oxlintrc.jsonc # check .oxlintrc.jsonc is removed
34+
> test ! -f .oxfmtrc.jsonc # check .oxfmtrc.jsonc is removed
35+
> cat package.json # check package.json
36+
{
37+
"devDependencies": {
38+
"vite-plus": "latest"
39+
},
40+
"pnpm": {
41+
"overrides": {
42+
"vite": "npm:@voidzero-dev/vite-plus-core@latest",
43+
"vitest": "npm:@voidzero-dev/vite-plus-test@latest"
44+
}
45+
},
46+
"packageManager": "pnpm@<semver>",
47+
"scripts": {
48+
"prepare": "vp config"
49+
}
50+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"commands": [
3+
"vp migrate --no-interactive 2>&1 # migration should detect .oxlintrc.jsonc and .oxfmtrc.jsonc",
4+
"cat vite.config.ts # check vite.config.ts",
5+
"test ! -f .oxlintrc.jsonc # check .oxlintrc.jsonc is removed",
6+
"test ! -f .oxfmtrc.jsonc # check .oxfmtrc.jsonc is removed",
7+
"cat package.json # check package.json"
8+
]
9+
}

packages/cli/src/migration/detector.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export function detectConfigs(projectPath: string): ConfigFiles {
9999

100100
// Check for oxlint configs
101101
// https://oxc.rs/docs/guide/usage/linter/config.html#configuration-file-format
102-
const oxlintConfigs = ['.oxlintrc.json'];
102+
const oxlintConfigs = ['.oxlintrc.json', '.oxlintrc.jsonc'];
103103
for (const config of oxlintConfigs) {
104104
if (fs.existsSync(path.join(projectPath, config))) {
105105
configs.oxlintConfig = config;

0 commit comments

Comments
 (0)