Skip to content

Commit 65b55b8

Browse files
committed
feat: merge oxlint config
1 parent 9fffc2c commit 65b55b8

14 files changed

Lines changed: 1498 additions & 407 deletions

File tree

Cargo.lock

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ anyhow = "1.0.98"
3939
# Safe to migrate back to the official ast-grep release once PR #2359 is merged and a new version is published.
4040
ast-grep-config = { git = "https://github.com/fengmk2/ast-grep.git", rev = "2f4c6924438a72e136485f0e14cd136b2e17d8d3" }
4141
ast-grep-core = { git = "https://github.com/fengmk2/ast-grep.git", rev = "2f4c6924438a72e136485f0e14cd136b2e17d8d3" }
42-
ast-grep-language = { git = "https://github.com/fengmk2/ast-grep.git", rev = "2f4c6924438a72e136485f0e14cd136b2e17d8d3", default-features = false, features = ["lang-bash"] }
42+
ast-grep-language = { git = "https://github.com/fengmk2/ast-grep.git", rev = "2f4c6924438a72e136485f0e14cd136b2e17d8d3", default-features = false, features = ["lang-bash", "lang-typescript"] }
4343
backon = "1.3.0"
4444
bincode = "2.0.1"
4545
bstr = { version = "1.12.0", default-features = false, features = ["alloc", "std"] }
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
# ast-grep rules for migrating .oxlintrc configuration to vite.config.ts
2+
#
3+
# These rules merge oxlint configuration from .oxlintrc into the defineConfig
4+
# call in vite.config.ts, following the vite-plus unified configuration approach.
5+
#
6+
# Usage:
7+
# The migration script should:
8+
# 1. Read .oxlintrc JSON content
9+
# 2. Convert it to TypeScript object literal format
10+
# 3. Replace __OXLINT_CONFIG__ placeholder with the actual config
11+
# 4. Run: sg scan -r oxlint-config.yaml vite.config.ts -U
12+
#
13+
# Example workflow:
14+
#
15+
# # Step 1: Create rule file with actual oxlint config
16+
# cat > /tmp/migrate-oxlint.yaml << 'EOF'
17+
# ---
18+
# id: merge-oxlint-config
19+
# language: TypeScript
20+
# rule:
21+
# pattern: |
22+
# defineConfig({
23+
# $$$CONFIG
24+
# })
25+
# fix: |-
26+
# defineConfig({
27+
# $$$CONFIG
28+
# lint: {
29+
# rules: {
30+
# 'no-unused-vars': 'error',
31+
# 'no-console': 'warn',
32+
# },
33+
# ignorePatterns: ['dist', 'node_modules'],
34+
# },
35+
# })
36+
# EOF
37+
#
38+
# # Step 2: Run ast-grep
39+
# sg scan -r /tmp/migrate-oxlint.yaml vite.config.ts -U
40+
#
41+
# # Step 3: Remove old config file
42+
# rm .oxlintrc
43+
#
44+
# For programmatic usage, use the vite_migration Rust crate which provides
45+
# proper JSON to TypeScript conversion.
46+
47+
# Rule 1: Add lint config to defineConfig with existing properties
48+
# Matches:
49+
# defineConfig({
50+
# plugins: [...],
51+
# server: {...},
52+
# })
53+
# Result:
54+
# defineConfig({
55+
# plugins: [...],
56+
# server: {...},
57+
# lint: {...},
58+
# })
59+
---
60+
id: add-lint-config-to-defineconfig
61+
language: TypeScript
62+
severity: info
63+
message: 'Add lint configuration to vite.config.ts'
64+
note: 'Migrating oxlint configuration from .oxlintrc to vite.config.ts'
65+
rule:
66+
pattern: |
67+
defineConfig({
68+
$$$EXISTING_CONFIG
69+
})
70+
fix: |-
71+
defineConfig({
72+
$$$EXISTING_CONFIG
73+
// lint configuration (merged from .oxlintrc)
74+
lint: __OXLINT_CONFIG__,
75+
})
76+
files:
77+
- '**/vite.config.ts'
78+
- '**/vite.config.mts'
79+
- '**/vite.config.js'
80+
- '**/vite.config.mjs'
81+
ignores:
82+
- '**/node_modules/**'
83+
- '**/dist/**'
84+
85+
# Rule 2: Detect defineConfig with function callback (warning only)
86+
# This pattern requires manual migration
87+
# Matches: defineConfig((env) => ({ ... }))
88+
---
89+
id: detect-function-defineconfig
90+
language: TypeScript
91+
severity: warning
92+
message: 'defineConfig uses a function callback - manual migration required'
93+
note: |
94+
The defineConfig uses a function callback pattern which cannot be
95+
automatically migrated. Please manually add the lint configuration:
96+
97+
export default defineConfig((env) => ({
98+
...existingConfig,
99+
lint: {
100+
rules: {
101+
// your rules from .oxlintrc
102+
},
103+
},
104+
}));
105+
rule:
106+
# Using explicit arrow function pattern to match callback style
107+
pattern: defineConfig(($PARAMS) => $BODY)
108+
files:
109+
- '**/vite.config.ts'
110+
- '**/vite.config.mts'
111+
- '**/vite.config.js'
112+
- '**/vite.config.mjs'
113+
ignores:
114+
- '**/node_modules/**'
115+
- '**/dist/**'
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Simple ast-grep rule for adding lint config to defineConfig
2+
#
3+
# This rule is designed to be used programmatically where the
4+
# __OXLINT_CONFIG__ placeholder is replaced with actual content.
5+
#
6+
# Usage:
7+
# 1. Read .oxlintrc content and convert to TypeScript
8+
# 2. Replace __OXLINT_CONFIG__ in this file with the converted content
9+
# 3. Run: sg scan -r oxlint-simple.yaml vite.config.ts -U
10+
#
11+
# Example:
12+
# # Create a rule with actual config content
13+
# cat > /tmp/oxlint-rule.yaml << 'EOF'
14+
# ---
15+
# id: merge-oxlint-to-vite-config
16+
# language: TypeScript
17+
# rule:
18+
# pattern: |
19+
# defineConfig({
20+
# $$$CONFIG
21+
# })
22+
# fix: |-
23+
# defineConfig({
24+
# $$$CONFIG
25+
# lint: {
26+
# rules: {
27+
# 'no-console': 'warn',
28+
# },
29+
# },
30+
# })
31+
# EOF
32+
# sg scan -r /tmp/oxlint-rule.yaml vite.config.ts -U
33+
#
34+
# Note: This rule handles the common case where defineConfig receives
35+
# an object literal directly. For function callbacks or complex patterns,
36+
# manual migration may be needed.
37+
38+
---
39+
id: merge-oxlint-to-vite-config
40+
language: TypeScript
41+
severity: info
42+
message: 'Merge .oxlintrc configuration into vite.config.ts'
43+
note: |
44+
This rule adds the lint configuration from .oxlintrc to the
45+
defineConfig call in vite.config.ts.
46+
47+
Before: defineConfig({ plugins: [...] })
48+
After: defineConfig({ plugins: [...], lint: {...} })
49+
50+
rule:
51+
# Match defineConfig call with object argument
52+
# Using multiline pattern to correctly capture the content
53+
pattern: |
54+
defineConfig({
55+
$$$CONFIG
56+
})
57+
58+
fix: |-
59+
defineConfig({
60+
$$$CONFIG
61+
// lint configuration (migrated from .oxlintrc)
62+
lint: __OXLINT_CONFIG__,
63+
})
64+
65+
files:
66+
- '**/vite.config.ts'
67+
- '**/vite.config.mts'
68+
- '**/vite.config.js'
69+
- '**/vite.config.mjs'
70+
ignores:
71+
- '**/node_modules/**'
72+
- '**/dist/**'

crates/vite_migration/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
mod package;
2+
mod vite_config;
23

34
pub use package::rewrite_scripts;
5+
pub use vite_config::{MergeResult, merge_json_config};

0 commit comments

Comments
 (0)