Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion packages/cli/binding/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,11 +292,23 @@ impl SubcommandResolver {
&owned_resolved_vite_config
};

if let (Some(_), Some(config_file)) =
if let (Some(fmt_config), Some(config_file)) =
(&resolved_vite_config.fmt, &resolved_vite_config.config_file)
{
args.insert(0, "-c".to_string());
args.insert(1, config_file.clone());

// Avoid "Expected at least one target file" error when
// ignorePatterns filters out all input files (e.g., `vp staged`
// passes only package-lock.json which is then excluded).
if fmt_config
.get("ignorePatterns")
.and_then(|v| v.as_array())
.is_some_and(|arr| !arr.is_empty())
&& !has_flag_before_terminator(&args, "--no-error-on-unmatched-pattern")
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding --no-error-on-unmatched-pattern, seemed to make the most sense to handle this.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@leaysgur Can this fix be implemented by oxfmt itself?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This flag exists for a reason, so it should be explicitly specified by the
caller who knows that zero matches are expected.

https://oxc.rs/docs/guide/usage/formatter/ci.html#pre-commit-hook

{
args.push("--no-error-on-unmatched-pattern".to_string());
}
}

Ok(ResolvedSubcommand {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "@test/fmt-ignore-patterns-all-excluded",
"version": "1.0.0",
"private": true,
"type": "module"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
> vp fmt src/ # Test that fmt exits 0 when all input files are excluded by ignorePatterns
Finished in <variable>ms on 0 files using <variable> threads.
No files found matching the given patterns.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// This file is excluded by ignorePatterns
function ignored() {
return 'hello';
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"commands": [
"vp fmt src/ # Test that fmt exits 0 when all input files are excluded by ignorePatterns"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default {
fmt: {
ignorePatterns: ['src/**/*'],
},
};