Skip to content

Commit 7be8a79

Browse files
committed
feat(check): pass --no-error-on-unmatched-pattern to oxlint natively
Now that oxlint supports --no-error-on-unmatched-pattern, pass it directly instead of working around it at the vp check level. Simplify the lint None branch to match the fmt pattern. Add snap tests for `vp check --fix package.json` (non-lintable file, should pass) and `vp lint package.json` (should exit non-zero).
1 parent 53913e0 commit 7be8a79

File tree

7 files changed

+26
-12
lines changed

7 files changed

+26
-12
lines changed

packages/cli/binding/src/check/mod.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,9 @@ pub(crate) async fn execute_check(
140140
// parser think linting never started. Force the default reporter here so the
141141
// captured output is stable across local and CI environments.
142142
args.push("--format=default".to_string());
143+
if suppress_unmatched {
144+
args.push("--no-error-on-unmatched-pattern".to_string());
145+
}
143146
if has_paths {
144147
args.extend(paths.iter().cloned());
145148
}
@@ -190,12 +193,11 @@ pub(crate) async fn execute_check(
190193
));
191194
}
192195
None => {
193-
// Only suppress when the output is empty (no files to lint).
194-
// If oxlint produced error output (config error, crash, etc.),
195-
// surface it even when suppress_unmatched is active.
196-
if suppress_unmatched && combined_output.trim().is_empty() {
197-
status = ExitStatus::SUCCESS;
198-
} else {
196+
// oxlint handles --no-error-on-unmatched-pattern natively and
197+
// exits 0 when no files match, so we only need to guard
198+
// against the edge case where output is unparsable but the
199+
// process still succeeded.
200+
if !(suppress_unmatched && status == ExitStatus::SUCCESS) {
199201
output::error("Linting could not start");
200202
if !combined_output.trim().is_empty() {
201203
print_stdout_block(&combined_output);
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
> vp check --fix src/ignored/index.js # all files excluded by ignorePatterns, should pass in --fix mode
22
pass: Formatting completed for checked files (<variable>ms)
3-
pass: Found no warnings or lint errors in 0 files (<variable>ms, <variable> threads)
43

5-
> vp check --no-error-on-unmatched-pattern src/ignored/index.js # explicit flag without --fix, should also pass
6-
pass: Found no warnings or lint errors in 0 files (<variable>ms, <variable> threads)
4+
> vp check --fix package.json # non-lintable file, should pass in --fix mode
5+
pass: Formatting completed for checked files (<variable>ms)
76

7+
> vp check --no-error-on-unmatched-pattern src/ignored/index.js # explicit flag without --fix, should also pass
88
> vp check --fix --no-error-on-unmatched-pattern src/ignored/index.js # both flags set, should pass
99
pass: Formatting completed for checked files (<variable>ms)
10-
pass: Found no warnings or lint errors in 0 files (<variable>ms, <variable> threads)
1110

1211
[2]> vp check src/ignored/index.js # without --fix or explicit flag, should exit non-zero
1312
error: Formatting could not start
14-
Expected at least one target file
13+
Checking formatting...
14+
Expected at least one target file. All matched files may have been excluded by ignore rules.
1515

1616
Formatting failed before analysis started

packages/cli/snap-tests/check-fix-no-error-unmatched/steps.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"commands": [
33
"vp check --fix src/ignored/index.js # all files excluded by ignorePatterns, should pass in --fix mode",
4+
"vp check --fix package.json # non-lintable file, should pass in --fix mode",
45
"vp check --no-error-on-unmatched-pattern src/ignored/index.js # explicit flag without --fix, should also pass",
56
"vp check --fix --no-error-on-unmatched-pattern src/ignored/index.js # both flags set, should pass",
67
"vp check src/ignored/index.js # without --fix or explicit flag, should exit non-zero"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "lint-unmatched-pattern",
3+
"version": "0.0.0",
4+
"private": true
5+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[1]> vp lint package.json # non-lintable file, should exit non-zero
2+
No files found to lint. Please check your paths and ignore patterns.
3+
Finished in <variable>ms on 0 files with <variable> rules using <variable> threads.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"commands": ["vp lint package.json # non-lintable file, should exit non-zero"]
3+
}

rfcs/check-command.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ When file paths are provided:
7676

7777
- Paths are appended to both `fmt` and `lint` sub-commands
7878
- In `--fix` mode, `--no-error-on-unmatched-pattern` is implicitly enabled for both `fmt` and `lint`, preventing errors when all provided paths are excluded by ignorePatterns. This is the common lint-staged use case where staged files may not match tool-specific patterns.
79-
- Without `--fix`, unmatched patterns are reported as errors unless `--no-error-on-unmatched-pattern` is explicitly passed. Note that oxfmt supports this flag natively, while oxlint does not — `vp check` handles the lint side by treating unparsable lint output as a pass when the flag is active.
79+
- Without `--fix`, unmatched patterns are reported as errors unless `--no-error-on-unmatched-pattern` is explicitly passed. Both oxfmt and oxlint support this flag natively.
8080

8181
This enables lint-staged integration:
8282

0 commit comments

Comments
 (0)