Skip to content

Commit e724b4d

Browse files
nickytonlineclaude
andcommitted
fix(cli): exit 0 when all fmt input files are excluded by ignorePatterns
When `vp staged` passes files to `vp fmt` that are all excluded by ignorePatterns in vite.config.ts (e.g., package-lock.json), oxfmt would error with "Expected at least one target file". Now vp fmt automatically adds `--no-error-on-unmatched-pattern` when the fmt config has ignorePatterns, so it exits 0 gracefully instead. Closes #1210 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent a3c80d5 commit e724b4d

File tree

6 files changed

+35
-1
lines changed

6 files changed

+35
-1
lines changed

packages/cli/binding/src/cli.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,11 +292,23 @@ impl SubcommandResolver {
292292
&owned_resolved_vite_config
293293
};
294294

295-
if let (Some(_), Some(config_file)) =
295+
if let (Some(fmt_config), Some(config_file)) =
296296
(&resolved_vite_config.fmt, &resolved_vite_config.config_file)
297297
{
298298
args.insert(0, "-c".to_string());
299299
args.insert(1, config_file.clone());
300+
301+
// Avoid "Expected at least one target file" error when
302+
// ignorePatterns filters out all input files (e.g., `vp staged`
303+
// passes only package-lock.json which is then excluded).
304+
if fmt_config
305+
.get("ignorePatterns")
306+
.and_then(|v| v.as_array())
307+
.is_some_and(|arr| !arr.is_empty())
308+
&& !has_flag_before_terminator(&args, "--no-error-on-unmatched-pattern")
309+
{
310+
args.push("--no-error-on-unmatched-pattern".to_string());
311+
}
300312
}
301313

302314
Ok(ResolvedSubcommand {
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name": "@test/fmt-ignore-patterns-all-excluded",
3+
"version": "1.0.0",
4+
"private": true,
5+
"type": "module"
6+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
> vp fmt src/ # Test that fmt exits 0 when all input files are excluded by ignorePatterns
2+
No files found matching the given patterns.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// This file is excluded by ignorePatterns
2+
function ignored() {
3+
return 'hello';
4+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"commands": [
3+
"vp fmt src/ # Test that fmt exits 0 when all input files are excluded by ignorePatterns"
4+
]
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export default {
2+
fmt: {
3+
ignorePatterns: ['src/**/*'],
4+
},
5+
};

0 commit comments

Comments
 (0)