Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow empty result from changed vcs files #1776

Merged
merged 4 commits into from
Mar 4, 2024
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b

```
Contributed by @ematipico
- Fix [#1774](https://github.com/biomejs/biome/issues/1774) by taking into account the option `--no-errors-on-unmatched` when running the CLI using `--changed`. Contributed by @antogyn

#### Enhancements

Expand Down
4 changes: 0 additions & 4 deletions crates/biome_cli/src/changed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,5 @@ pub(crate) fn get_changed_files(

let filtered_changed_files = changed_files.iter().map(OsString::from).collect::<Vec<_>>();

if filtered_changed_files.is_empty() {
Copy link
Member

Choose a reason for hiding this comment

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

I believe this check should stay, but we need to add the check if no_errors_on_unmatched is true

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've re-added this check, but now it's done twice - once here, and once in traverse.rs

return Err(CliDiagnostic::no_files_processed());
}

Ok(filtered_changed_files)
}
5 changes: 4 additions & 1 deletion crates/biome_cli/src/execute/traverse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,10 @@ pub(crate) fn traverse(
inputs: Vec<OsString>,
) -> Result<(), CliDiagnostic> {
init_thread_pool();
if inputs.is_empty() && execution.as_stdin_file().is_none() {
if inputs.is_empty()
&& execution.as_stdin_file().is_none()
&& !cli_options.no_errors_on_unmatched
{
return Err(CliDiagnostic::missing_argument(
"<INPUT>",
format!("{}", execution.traversal_mode),
Expand Down
38 changes: 38 additions & 0 deletions crates/biome_cli/tests/commands/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2683,6 +2683,44 @@ fn should_not_process_ignored_file_even_if_its_changed() {
));
}

#[test]
fn should_not_error_for_no_changed_files_with_no_errors_on_unmatched() {
let mut console = BufferConsole::default();
let mut fs = MemoryFileSystem::default();

let file_path = Path::new("file.js");
fs.insert(file_path.into(), r#"console.log('file');"#.as_bytes());

let file_path2 = Path::new("file2.js");
fs.insert(file_path2.into(), r#"console.log('file2');"#.as_bytes());

let result = run_cli(
DynRef::Borrowed(&mut fs),
&mut console,
Args::from(
[
("lint"),
"--changed",
"--since=main",
"--no-errors-on-unmatched",
file_path.as_os_str().to_str().unwrap(),
file_path2.as_os_str().to_str().unwrap(),
]
.as_slice(),
),
);

assert!(result.is_ok(), "run_cli returned {result:?}");

assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
"should_not_error_for_no_changed_files_with_no_errors_on_unmatched",
fs,
console,
result,
));
}

#[test]
fn lint_syntax_rules() {
let mut fs = MemoryFileSystem::default();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
source: crates/biome_cli/tests/snap_test.rs
expression: content
---
## `file.js`

```js
console.log('file');
```

## `file2.js`

```js
console.log('file2');
```

# Emitted Messages

```block
Checked 0 file(s) in <TIME>
```


4 changes: 3 additions & 1 deletion crates/biome_fs/src/fs/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ impl Default for MemoryFileSystem {
files: Default::default(),
errors: Default::default(),
allow_write: true,
on_get_changed_files: None,
on_get_changed_files: Some(Arc::new(AssertUnwindSafe(Mutex::new(Some(Box::new(
|| vec![],
)))))),
}
}
}
Expand Down
1 change: 1 addition & 0 deletions website/src/content/docs/internals/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b

```
Contributed by @ematipico
- Fix [#1774](https://github.com/biomejs/biome/issues/1774) by taking into account the option `--no-errors-on-unmatched` when running the CLI using `--changed`. Contributed by @antogyn

#### Enhancements

Expand Down
Loading