Skip to content

Commit

Permalink
fix(cli): return the original content when a protected file is encoun…
Browse files Browse the repository at this point in the history
…tered (#1542)
  • Loading branch information
ematipico authored Jan 12, 2024
1 parent e7fe085 commit 0d85d6f
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Read our [guidelines for writing a good changelog entry](https://github.com/biom
- Fix [#1512](https://github.com/biomejs/biome/issues/1512) by skipping verbose diagnostics from the count. Contributed by @ematipico
- Don't handle CSS files, the formatter isn't ready yet. Contributed by @ematipico
- The file `biome.json` can't be ignored anymore. Contributed by @ematipico
- Fix [#1541](https://github.com/biomejs/biome/issues/1541) where the content of protected files wasn't returned to `stdout`. Contributed by @ematipico

### Configuration

Expand Down
14 changes: 10 additions & 4 deletions crates/biome_cli/src/execute/std_in.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,14 @@ pub(crate) fn run<'a>(
if file_features.is_protected() {
let protected_diagnostic =
WorkspaceError::protected_file(rome_path.display().to_string());
if protected_diagnostic.tags().is_verbose() && verbose {
console.error(markup! {{PrintDiagnostic::verbose(&protected_diagnostic)}})
if protected_diagnostic.tags().is_verbose() {
if verbose {
console.error(markup! {{PrintDiagnostic::verbose(&protected_diagnostic)}})
}
} else {
console.error(markup! {{PrintDiagnostic::simple(&protected_diagnostic)}})
}
console.append(markup! {{content}});
return Ok(());
};
if file_features.supports_for(&FeatureName::Format) {
Expand Down Expand Up @@ -84,11 +87,14 @@ pub(crate) fn run<'a>(
if file_features.is_protected() {
let protected_diagnostic =
WorkspaceError::protected_file(rome_path.display().to_string());
if protected_diagnostic.tags().is_verbose() && verbose {
console.error(markup! {{PrintDiagnostic::verbose(&protected_diagnostic)}})
if protected_diagnostic.tags().is_verbose() {
if verbose {
console.error(markup! {{PrintDiagnostic::verbose(&protected_diagnostic)}})
}
} else {
console.error(markup! {{PrintDiagnostic::simple(&protected_diagnostic)}})
}
console.append(markup! {{content}});
return Ok(());
};

Expand Down
40 changes: 38 additions & 2 deletions crates/biome_cli/tests/cases/protected_files.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::run_cli;
use crate::snap_test::{assert_cli_snapshot, SnapshotPayload};
use biome_console::BufferConsole;
use crate::snap_test::{assert_cli_snapshot, markup_to_string, SnapshotPayload};
use biome_console::{markup, BufferConsole};
use biome_fs::MemoryFileSystem;
use biome_service::DynRef;
use bpaf::Args;
Expand Down Expand Up @@ -157,3 +157,39 @@ fn not_process_file_from_cli_verbose() {
result,
));
}

#[test]
fn should_return_the_content_of_protected_files_via_stdin() {
let mut fs = MemoryFileSystem::default();
let mut console = BufferConsole::default();
console
.in_buffer
.push(r#"{ "name": "something" }"#.to_string());

let result = run_cli(
DynRef::Borrowed(&mut fs),
&mut console,
Args::from([("format"), ("--stdin-file-path"), ("package.json")].as_slice()),
);

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

let message = console
.out_buffer
.first()
.expect("Console should have written a message");

let content = markup_to_string(markup! {
{message.content}
});

assert_eq!(content, r#"{ "name": "something" }"#);

assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
"should_return_the_content_of_protected_files_via_stdin",
fs,
console,
result,
));
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ expression: content
# Emitted Messages

```block
package.json project VERBOSE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
i The file package.json is protected because is handled by another tool. Biome won't process it.
{ "name": "test" }
```


Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ expression: content
# Emitted Messages

```block
package.json project VERBOSE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
i The file package.json is protected because is handled by another tool. Biome won't process it.
{ "name": "test" }
```


Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@ package.json project VERBOSE ━━━━━━━━━━━━━━━━
```

```block
{ "name": "test" }
```


Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@ package.json project VERBOSE ━━━━━━━━━━━━━━━━
```

```block
{ "name": "test" }
```


Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
source: crates/biome_cli/tests/snap_test.rs
expression: content
---
# Input messages

```block
{ "name": "something" }
```

# Emitted Messages

```block
{ "name": "something" }
```


1 change: 1 addition & 0 deletions website/src/content/docs/internals/changelog.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Read our [guidelines for writing a good changelog entry](https://github.com/biom
- Fix [#1512](https://github.com/biomejs/biome/issues/1512) by skipping verbose diagnostics from the count. Contributed by @ematipico
- Don't handle CSS files, the formatter isn't ready yet. Contributed by @ematipico
- The file `biome.json` can't be ignored anymore. Contributed by @ematipico
- Fix [#1541](https://github.com/biomejs/biome/issues/1541) where the content of protected files wasn't returned to `stdout`. Contributed by @ematipico

### Configuration

Expand Down

0 comments on commit 0d85d6f

Please sign in to comment.