Skip to content

Commit

Permalink
fix: allow empty result from changed vcs files (#1776)
Browse files Browse the repository at this point in the history
Co-authored-by: Anthony Giniers <[email protected]>
Co-authored-by: Emanuele Stoppa <[email protected]>
  • Loading branch information
3 people authored Mar 4, 2024
1 parent 59b0330 commit b95f83e
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 6 deletions.
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() {
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

0 comments on commit b95f83e

Please sign in to comment.