Skip to content
Merged
58 changes: 35 additions & 23 deletions crates/biome_cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,35 +110,35 @@ pub enum BiomeCommand {
/// Runs formatter, linter and import sorting to the requested files.
#[bpaf(command)]
Check {
/// Writes safe fixes, formatting and import sorting
/// Apply safe fixes, formatting and import sorting
#[bpaf(long("write"), switch)]
write: bool,

/// Allow to do unsafe fixes, should be used with `--write` or `--fix`
/// Apply unsafe fixes. Should be used with `--write` or `--fix`
#[bpaf(long("unsafe"), switch)]
unsafe_: bool,

/// Alias for `--write`, writes safe fixes, formatting and import sorting
#[bpaf(long("fix"), switch, hide_usage)]
fix: bool,

/// Allow to enable or disable the formatter check.
/// Allow enabling or disabling the formatter check.
#[bpaf(
long("formatter-enabled"),
argument("true|false"),
optional,
hide_usage
)]
formatter_enabled: Option<FormatterEnabled>,
/// Allow to enable or disable the linter check.
/// Allow enabling or disabling the linter check.
#[bpaf(long("linter-enabled"), argument("true|false"), optional, hide_usage)]
linter_enabled: Option<LinterEnabled>,

/// Allow to enable or disable the assist.
/// Allow enabling or disabling the assist.
#[bpaf(long("assist-enabled"), argument("true|false"), optional)]
assist_enabled: Option<AssistEnabled>,

/// Allows to enforce assist, and make the CLI fail if some actions aren't applied. Defaults to `true`.
/// Allows enforcing assist, and make the CLI fail if some actions aren't applied. Defaults to `true`.
#[bpaf(long("enforce-assist"), argument("true|false"), fallback(true))]
enforce_assist: bool,

Expand All @@ -150,7 +150,10 @@ pub enum BiomeCommand {
///
/// The file doesn't need to exist on disk, what matters is the extension of the file. Based on the extension, Biome knows how to check the code.
///
/// Example: `echo 'let a;' | biome check --stdin-file-path=file.js`
/// Example:
/// ```shell
/// echo 'let a;' | biome check --stdin-file-path=file.js --write
/// ```
#[bpaf(long("stdin-file-path"), argument("PATH"), hide_usage)]
stdin_file_path: Option<String>,

Expand Down Expand Up @@ -180,15 +183,15 @@ pub enum BiomeCommand {
#[bpaf(long("write"), switch)]
write: bool,

/// Allow to do unsafe fixes, should be used with `--write` or `--fix`
/// Apply unsafe fixes. Should be used with `--write` or `--fix`
#[bpaf(long("unsafe"), switch)]
unsafe_: bool,

/// Alias for `--write`, writes safe fixes
#[bpaf(long("fix"), switch, hide_usage)]
fix: bool,

/// Fixes lint rule violations with a comment a suppression instead of using a rule code action (fix)
/// Fixes lint rule violations with comment suppressions instead of using a rule code action (fix)
#[bpaf(long("suppress"))]
suppress: bool,

Expand Down Expand Up @@ -239,7 +242,10 @@ pub enum BiomeCommand {
///
/// The file doesn't need to exist on disk, what matters is the extension of the file. Based on the extension, Biome knows how to lint the code.
///
/// Example: `echo 'let a;' | biome lint --stdin-file-path=file.js`
/// Example:
/// ```shell
/// echo 'let a;' | biome lint --stdin-file-path=file.js --write
/// ```
#[bpaf(long("stdin-file-path"), argument("PATH"), hide_usage)]
stdin_file_path: Option<String>,
/// When set to true, only the files that have been staged (the ones prepared to be committed)
Expand Down Expand Up @@ -288,18 +294,21 @@ pub enum BiomeCommand {
///
/// The file doesn't need to exist on disk, what matters is the extension of the file. Based on the extension, Biome knows how to format the code.
///
/// Example: `echo 'let a;' | biome format --stdin-file-path=file.js`
/// Example:
/// ```shell
/// echo 'let a;' | biome format --stdin-file-path=file.js --write
/// ```
#[bpaf(long("stdin-file-path"), argument("PATH"), hide_usage)]
stdin_file_path: Option<String>,

#[bpaf(external, hide_usage)]
cli_options: CliOptions,

/// Writes formatted files to file system.
/// Writes formatted files to a file system.
#[bpaf(long("write"), switch)]
write: bool,

/// Alias of `--write`, writes formatted files to file system.
/// Alias of `--write`, writes formatted files to a file system.
#[bpaf(long("fix"), switch, hide_usage)]
fix: bool,

Expand All @@ -314,7 +323,7 @@ pub enum BiomeCommand {
changed: bool,

/// Use this to specify the base branch to compare against when you're using the --changed
/// flag and the `defaultBranch` is not set in your biome.json
/// flag, and the `defaultBranch` is not set in your biome.json
#[bpaf(long("since"), argument("REF"))]
since: Option<String>,

Expand All @@ -327,19 +336,19 @@ pub enum BiomeCommand {
/// Files won't be modified, the command is a read-only operation.
#[bpaf(command)]
Ci {
/// Allow to enable or disable the formatter check.
/// Allow enabling or disabling the formatter check.
#[bpaf(long("formatter-enabled"), argument("true|false"), optional)]
formatter_enabled: Option<FormatterEnabled>,
/// Allow to enable or disable the linter check.
/// Allow enabling or disable the linter check.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// Allow enabling or disable the linter check.
/// Allow enabling or disabling the linter check.

#[bpaf(long("linter-enabled"), argument("true|false"), optional)]
linter_enabled: Option<LinterEnabled>,

/// Allow to enable or disable the assist.
/// Allow enabling or disabling the assist.
#[bpaf(long("assist-enabled"), argument("true|false"), optional)]
assist_enabled: Option<AssistEnabled>,

/// Allows to enforce assist, and make the CLI fail if some actions aren't applied. Defaults to `true`.
#[bpaf(long("enforce-assist"), switch, fallback(true))]
/// Allows enforcing assist, and make the CLI fail if some actions aren't applied. Defaults to `true`.
#[bpaf(long("enforce-assist"), argument("true|false"), fallback(true))]
enforce_assist: bool,

#[bpaf(external(configuration), hide_usage, optional)]
Expand Down Expand Up @@ -453,7 +462,10 @@ pub enum BiomeCommand {
/// extension of the file. Based on the extension, Biome knows how to
/// parse the code.
///
/// Example: `echo 'let a;' | biome search '`let $var`' --stdin-file-path=file.js`
/// Example:
/// ```shell
/// echo 'let a;' | biome search '`let $var`' --stdin-file-path=file.js
/// ```
#[bpaf(long("stdin-file-path"), argument("PATH"), hide_usage)]
stdin_file_path: Option<String>,

Expand All @@ -463,7 +475,7 @@ pub enum BiomeCommand {
/// target, so we currently do not support writing queries that apply
/// to multiple languages at once.
///
/// If none given, the default language is JavaScript.
/// When none, the default language is JavaScript.
#[bpaf(long("language"), short('l'))]
language: Option<GritTargetLanguage>,

Expand Down Expand Up @@ -502,7 +514,7 @@ pub enum BiomeCommand {

#[bpaf(command("__run_server"), hide)]
RunServer {
/// Allows to change the prefix applied to the file name of the logs.
/// Allows changing the prefix applied to the file name of the logs.
#[bpaf(
env("BIOME_LOG_PREFIX_NAME"),
long("log-prefix-name"),
Expand All @@ -512,7 +524,7 @@ pub enum BiomeCommand {
display_fallback
)]
log_prefix_name: String,
/// Allows to change the folder where logs are stored.
/// Allows changing the folder where logs are stored.
#[bpaf(
env("BIOME_LOG_PATH"),
long("log-path"),
Expand Down
2 changes: 1 addition & 1 deletion crates/biome_cli/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ impl Diagnostic for StdinDiagnostic {
fn message(&self, fmt: &mut Formatter<'_>) -> std::io::Result<()> {
match self {
Self::NotFormatted => {
fmt.write_str("The contents aren't fixed. Use the `--fix` flag to fix them.")
fmt.write_str("The contents aren't fixed. Use the `--write` flag to fix them.")
},
Self::NoExtension => {
fmt.write_markup(markup!{
Expand Down
2 changes: 1 addition & 1 deletion crates/biome_cli/src/reporter/terminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl ReporterVisitor for ConsoleReporterVisitor<'_> {
if execution.is_check() && summary.suggested_fixes_skipped > 0 {
self.0.log(markup! {
<Warn>"Skipped "{summary.suggested_fixes_skipped}" suggested fixes.\n"</Warn>
<Info>"If you wish to apply the suggested (unsafe) fixes, use the command "<Emphasis>"biome check --fix --unsafe\n"</Emphasis></Info>
<Info>"If you wish to apply the suggested (unsafe) fixes, use the command "<Emphasis>"biome check --write --unsafe\n"</Emphasis></Info>
})
}

Expand Down
44 changes: 44 additions & 0 deletions crates/biome_cli/tests/cases/assist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,50 @@ fn assist_emit_diagnostic_and_blocks() {
));
}

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

let config = Utf8Path::new("biome.json");
fs.insert(
config.into(),
r#"{
"assist": {
"enabled": true,
"actions": {
"source": {
"useSortedKeys": "on"
}
}
},
"formatter": { "enabled": false }
}"#
.as_bytes(),
);
let file = Utf8Path::new("file.json");
fs.insert(
file.into(),
r#"{ "zod": true, "lorem": "ipsum", "foo": "bar" }"#.as_bytes(),
);

let (fs, result) = run_cli(
fs,
&mut console,
Args::from(["ci", file.as_str()].as_slice()),
);

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

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

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

```json
{
"assist": {
"enabled": true,
"actions": {
"source": {
"useSortedKeys": "on"
}
}
},
"formatter": { "enabled": false }
}
```

## `file.json`

```json
{ "zod": true, "lorem": "ipsum", "foo": "bar" }
```

# Termination Message

```block
ci ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

× Some errors were emitted while running checks.



```

# Emitted Messages

```block
file.json:1:1 assist/source/useSortedKeys FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

× The keys are not sorted.

> 1 │ { "zod": true, "lorem": "ipsum", "foo": "bar" }
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

i Safe fix: They keys of the current object can be sorted.

- {·"zod":·true,·"lorem":·"ipsum",·"foo":·"bar"·}
+ {·"foo":·"bar"·,"lorem":·"ipsum","zod":·true·}


```

```block
Checked 1 file in <TIME>. No fixes applied.
Found 1 error.
```
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: crates/biome_cli/tests/snap_test.rs
expression: content
expression: redactor(content)
---
# Input messages

Expand All @@ -20,7 +20,7 @@ var foo: string = "";
```block
stdin ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

× The contents aren't fixed. Use the `--fix` flag to fix them.
× The contents aren't fixed. Use the `--write` flag to fix them.



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export { a };
```block
stdin ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

× The contents aren't fixed. Use the `--fix` flag to fix them.
× The contents aren't fixed. Use the `--write` flag to fix them.



Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: crates/biome_cli/tests/snap_test.rs
expression: content
expression: redactor(content)
---
# Input messages

Expand All @@ -20,7 +20,7 @@ var foo: string = "";
```block
stdin ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

× The contents aren't fixed. Use the `--fix` flag to fix them.
× The contents aren't fixed. Use the `--write` flag to fix them.



Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: crates/biome_cli/tests/snap_test.rs
expression: content
expression: redactor(content)
---
# Input messages

Expand All @@ -16,7 +16,7 @@ var foo: string = "";
```block
stdin ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

× The contents aren't fixed. Use the `--fix` flag to fix them.
× The contents aren't fixed. Use the `--write` flag to fix them.



Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: crates/biome_cli/tests/snap_test.rs
expression: content
expression: redactor(content)
---
# Input messages

Expand All @@ -19,7 +19,7 @@ delete a.c;
```block
stdin ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

× The contents aren't fixed. Use the `--fix` flag to fix them.
× The contents aren't fixed. Use the `--write` flag to fix them.



Expand Down
Loading
Loading