Skip to content

Commit d579500

Browse files
committed
refactor(cli): use native lint and fmt config discovery
1 parent 6089186 commit d579500

25 files changed

Lines changed: 479 additions & 83 deletions

File tree

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"singleQuote": false,
3+
"semi": true
4+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"rules": {
3+
"no-console": "off"
4+
}
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "oxc-config-auto-discovery",
3+
"private": true,
4+
"type": "module"
5+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
[[case]]
2+
name = "discover_root_config"
3+
vp = ["local", "global"]
4+
steps = [
5+
{ argv = ["vp", "lint", "src"], comment = "The root lint config enables no-console.", continue-on-failure = true },
6+
{ argv = ["vp", "fmt", "src"] },
7+
{ argv = ["vpt", "print-file", "src/index.js"], comment = "The root fmt config selects single quotes and no semicolons." },
8+
{ argv = ["vp", "check", "src"], comment = "The composite command uses the same discovered settings.", continue-on-failure = true },
9+
]
10+
11+
[[case]]
12+
name = "explicit_config"
13+
vp = ["local", "global"]
14+
steps = [
15+
{ argv = ["vp", "lint", "-c", "custom-lint.json", "src"], comment = "An explicit lint config overrides the root config." },
16+
{ argv = ["vp", "fmt", "--config", "custom-fmt.json", "src"] },
17+
{ argv = ["vpt", "print-file", "src/index.js"], comment = "The explicit fmt config keeps double quotes and semicolons." },
18+
{ argv = ["vp", "lint", "--config=custom-lint.json", "src"] },
19+
{ argv = ["vp", "fmt", "-c", "custom-fmt.json", "--check", "src"] },
20+
]
21+
22+
[[case]]
23+
name = "discover_config_from_subdirectory"
24+
vp = "local"
25+
steps = [
26+
{ argv = ["vpt", "write-file", "src/vite.config.ts", "export default {};\n"] },
27+
{ argv = ["vp", "lint", "index.js"], cwd = "src", comment = "A config without lint settings is skipped in favor of the parent config.", continue-on-failure = true },
28+
{ argv = ["vp", "fmt", "index.js"], cwd = "src" },
29+
{ argv = ["vpt", "print-file", "src/index.js"], comment = "The parent fmt settings are discovered too." },
30+
{ argv = ["vpt", "write-file", "src/vite.config.ts", "export default { lint: { rules: { 'no-console': 'off' } }, fmt: { singleQuote: false, semi: true } };\n"] },
31+
{ argv = ["vp", "lint", "index.js"], cwd = "src", comment = "The config in the working directory takes precedence when it has lint settings." },
32+
{ argv = ["vp", "fmt", "index.js"], cwd = "src" },
33+
{ argv = ["vpt", "print-file", "src/index.js"], comment = "The working directory's fmt settings take precedence too." },
34+
{ argv = ["vp", "lint", "src/index.js"], comment = "Running from the root keeps per-file nested lint configs disabled.", continue-on-failure = true },
35+
{ argv = ["vp", "fmt", "src/index.js"] },
36+
{ argv = ["vpt", "print-file", "src/index.js"], comment = "Running from the root keeps per-file nested fmt configs disabled." },
37+
]
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# discover_config_from_subdirectory
2+
3+
## `vpt write-file src/vite.config.ts 'export default {};
4+
'`
5+
6+
```
7+
```
8+
9+
## `cd src && vp lint index.js`
10+
11+
A config without lint settings is skipped in favor of the parent config.
12+
13+
**Exit code:** 1
14+
15+
```
16+
17+
× eslint(no-console): Unexpected console statement.
18+
╭─[index.js:1:1]
19+
1 │ console.log("hello");
20+
· ───────────
21+
╰────
22+
help: Delete this console statement.
23+
24+
Found 0 warnings and 1 error.
25+
Finished in <duration> on 1 file with <n> rules using <n> threads.
26+
```
27+
28+
## `cd src && vp fmt index.js`
29+
30+
```
31+
Finished in <duration> on 1 files using <n> threads.
32+
```
33+
34+
## `vpt print-file src/index.js`
35+
36+
The parent fmt settings are discovered too.
37+
38+
```
39+
console.log('hello')
40+
```
41+
42+
## `vpt write-file src/vite.config.ts 'export default { lint: { rules: { '\''no-console'\'': '\''off'\'' } }, fmt: { singleQuote: false, semi: true } };
43+
'`
44+
45+
```
46+
```
47+
48+
## `cd src && vp lint index.js`
49+
50+
The config in the working directory takes precedence when it has lint settings.
51+
52+
```
53+
Found 0 warnings and 0 errors.
54+
Finished in <duration> on 1 file with <n> rules using <n> threads.
55+
```
56+
57+
## `cd src && vp fmt index.js`
58+
59+
```
60+
Finished in <duration> on 1 files using <n> threads.
61+
```
62+
63+
## `vpt print-file src/index.js`
64+
65+
The working directory's fmt settings take precedence too.
66+
67+
```
68+
console.log("hello");
69+
```
70+
71+
## `vp lint src/index.js`
72+
73+
Running from the root keeps per-file nested lint configs disabled.
74+
75+
**Exit code:** 1
76+
77+
```
78+
79+
× eslint(no-console): Unexpected console statement.
80+
╭─[src/index.js:1:1]
81+
1 │ console.log("hello");
82+
· ───────────
83+
╰────
84+
help: Delete this console statement.
85+
86+
Found 0 warnings and 1 error.
87+
Finished in <duration> on 1 file with <n> rules using <n> threads.
88+
```
89+
90+
## `vp fmt src/index.js`
91+
92+
```
93+
Finished in <duration> on 1 files using <n> threads.
94+
```
95+
96+
## `vpt print-file src/index.js`
97+
98+
Running from the root keeps per-file nested fmt configs disabled.
99+
100+
```
101+
console.log('hello')
102+
```
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# discover_root_config
2+
3+
## `vp lint src`
4+
5+
The root lint config enables no-console.
6+
7+
**Exit code:** 1
8+
9+
```
10+
VITE+ - The Unified Toolchain for the Web
11+
12+
× eslint(no-console): Unexpected console statement.
13+
╭─[src/index.js:1:1]
14+
1 │ console.log("hello");
15+
· ───────────
16+
╰────
17+
help: Delete this console statement.
18+
19+
Found 0 warnings and 1 error.
20+
Finished in <duration> on 1 file with <n> rules using <n> threads.
21+
```
22+
23+
## `vp fmt src`
24+
25+
```
26+
VITE+ - The Unified Toolchain for the Web
27+
28+
Finished in <duration> on 1 files using <n> threads.
29+
```
30+
31+
## `vpt print-file src/index.js`
32+
33+
The root fmt config selects single quotes and no semicolons.
34+
35+
```
36+
console.log('hello')
37+
```
38+
39+
## `vp check src`
40+
41+
The composite command uses the same discovered settings.
42+
43+
**Exit code:** 1
44+
45+
```
46+
VITE+ - The Unified Toolchain for the Web
47+
48+
pass: All 1 file are correctly formatted (<duration>, <n> threads)
49+
error: Lint issues found
50+
× eslint(no-console): Unexpected console statement.
51+
╭─[src/index.js:1:1]
52+
1 │ console.log('hello')
53+
· ───────────
54+
╰────
55+
help: Delete this console statement.
56+
57+
Found 1 error and 0 warnings in 1 file (<duration>, <n> threads)
58+
```
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# discover_root_config
2+
3+
## `vp lint src`
4+
5+
The root lint config enables no-console.
6+
7+
**Exit code:** 1
8+
9+
```
10+
11+
× eslint(no-console): Unexpected console statement.
12+
╭─[src/index.js:1:1]
13+
1 │ console.log("hello");
14+
· ───────────
15+
╰────
16+
help: Delete this console statement.
17+
18+
Found 0 warnings and 1 error.
19+
Finished in <duration> on 1 file with <n> rules using <n> threads.
20+
```
21+
22+
## `vp fmt src`
23+
24+
```
25+
Finished in <duration> on 1 files using <n> threads.
26+
```
27+
28+
## `vpt print-file src/index.js`
29+
30+
The root fmt config selects single quotes and no semicolons.
31+
32+
```
33+
console.log('hello')
34+
```
35+
36+
## `vp check src`
37+
38+
The composite command uses the same discovered settings.
39+
40+
**Exit code:** 1
41+
42+
```
43+
pass: All 1 file are correctly formatted (<duration>, <n> threads)
44+
error: Lint issues found
45+
× eslint(no-console): Unexpected console statement.
46+
╭─[src/index.js:1:1]
47+
1 │ console.log('hello')
48+
· ───────────
49+
╰────
50+
help: Delete this console statement.
51+
52+
Found 1 error and 0 warnings in 1 file (<duration>, <n> threads)
53+
```
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# explicit_config
2+
3+
## `vp lint -c custom-lint.json src`
4+
5+
An explicit lint config overrides the root config.
6+
7+
```
8+
VITE+ - The Unified Toolchain for the Web
9+
10+
Found 0 warnings and 0 errors.
11+
Finished in <duration> on 1 file with <n> rules using <n> threads.
12+
```
13+
14+
## `vp fmt --config custom-fmt.json src`
15+
16+
```
17+
VITE+ - The Unified Toolchain for the Web
18+
19+
Finished in <duration> on 1 files using <n> threads.
20+
```
21+
22+
## `vpt print-file src/index.js`
23+
24+
The explicit fmt config keeps double quotes and semicolons.
25+
26+
```
27+
console.log("hello");
28+
```
29+
30+
## `vp lint --config=custom-lint.json src`
31+
32+
```
33+
VITE+ - The Unified Toolchain for the Web
34+
35+
Found 0 warnings and 0 errors.
36+
Finished in <duration> on 1 file with <n> rules using <n> threads.
37+
```
38+
39+
## `vp fmt -c custom-fmt.json --check src`
40+
41+
```
42+
VITE+ - The Unified Toolchain for the Web
43+
44+
Checking formatting...
45+
46+
All matched files use the correct format.
47+
Finished in <duration> on 1 files using <n> threads.
48+
```
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# explicit_config
2+
3+
## `vp lint -c custom-lint.json src`
4+
5+
An explicit lint config overrides the root config.
6+
7+
```
8+
Found 0 warnings and 0 errors.
9+
Finished in <duration> on 1 file with <n> rules using <n> threads.
10+
```
11+
12+
## `vp fmt --config custom-fmt.json src`
13+
14+
```
15+
Finished in <duration> on 1 files using <n> threads.
16+
```
17+
18+
## `vpt print-file src/index.js`
19+
20+
The explicit fmt config keeps double quotes and semicolons.
21+
22+
```
23+
console.log("hello");
24+
```
25+
26+
## `vp lint --config=custom-lint.json src`
27+
28+
```
29+
Found 0 warnings and 0 errors.
30+
Finished in <duration> on 1 file with <n> rules using <n> threads.
31+
```
32+
33+
## `vp fmt -c custom-fmt.json --check src`
34+
35+
```
36+
Checking formatting...
37+
38+
All matched files use the correct format.
39+
Finished in <duration> on 1 files using <n> threads.
40+
```
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log("hello");

0 commit comments

Comments
 (0)