Skip to content

Commit e5826e6

Browse files
committed
fix(cli): correct type for enforce-assist
1 parent cb1005c commit e5826e6

File tree

12 files changed

+267
-149
lines changed

12 files changed

+267
-149
lines changed

crates/biome_cli/src/commands/mod.rs

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -110,35 +110,35 @@ pub enum BiomeCommand {
110110
/// Runs formatter, linter and import sorting to the requested files.
111111
#[bpaf(command)]
112112
Check {
113-
/// Writes safe fixes, formatting and import sorting
113+
/// Apply safe fixes, formatting and import sorting
114114
#[bpaf(long("write"), switch)]
115115
write: bool,
116116

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

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

125-
/// Allow to enable or disable the formatter check.
125+
/// Allow enabling or disable the formatter check.
126126
#[bpaf(
127127
long("formatter-enabled"),
128128
argument("true|false"),
129129
optional,
130130
hide_usage
131131
)]
132132
formatter_enabled: Option<FormatterEnabled>,
133-
/// Allow to enable or disable the linter check.
133+
/// Allow enabling or disable the linter check.
134134
#[bpaf(long("linter-enabled"), argument("true|false"), optional, hide_usage)]
135135
linter_enabled: Option<LinterEnabled>,
136136

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

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

@@ -150,7 +150,10 @@ pub enum BiomeCommand {
150150
///
151151
/// 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.
152152
///
153-
/// Example: `echo 'let a;' | biome check --stdin-file-path=file.js`
153+
/// Example:
154+
/// ```shell
155+
/// echo 'let a;' | biome check --stdin-file-path=file.js --write
156+
/// ```
154157
#[bpaf(long("stdin-file-path"), argument("PATH"), hide_usage)]
155158
stdin_file_path: Option<String>,
156159

@@ -180,15 +183,15 @@ pub enum BiomeCommand {
180183
#[bpaf(long("write"), switch)]
181184
write: bool,
182185

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

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

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

@@ -239,7 +242,10 @@ pub enum BiomeCommand {
239242
///
240243
/// 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.
241244
///
242-
/// Example: `echo 'let a;' | biome lint --stdin-file-path=file.js`
245+
/// Example:
246+
/// ```shell
247+
/// echo 'let a;' | biome lint --stdin-file-path=file.js --write
248+
/// ```
243249
#[bpaf(long("stdin-file-path"), argument("PATH"), hide_usage)]
244250
stdin_file_path: Option<String>,
245251
/// When set to true, only the files that have been staged (the ones prepared to be committed)
@@ -288,18 +294,21 @@ pub enum BiomeCommand {
288294
///
289295
/// 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.
290296
///
291-
/// Example: `echo 'let a;' | biome format --stdin-file-path=file.js`
297+
/// Example:
298+
/// ```shell
299+
/// echo 'let a;' | biome format --stdin-file-path=file.js --write
300+
/// ```
292301
#[bpaf(long("stdin-file-path"), argument("PATH"), hide_usage)]
293302
stdin_file_path: Option<String>,
294303

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

298-
/// Writes formatted files to file system.
307+
/// Writes formatted files to a file system.
299308
#[bpaf(long("write"), switch)]
300309
write: bool,
301310

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

@@ -314,7 +323,7 @@ pub enum BiomeCommand {
314323
changed: bool,
315324

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

@@ -327,19 +336,19 @@ pub enum BiomeCommand {
327336
/// Files won't be modified, the command is a read-only operation.
328337
#[bpaf(command)]
329338
Ci {
330-
/// Allow to enable or disable the formatter check.
339+
/// Allow enabling or disable the formatter check.
331340
#[bpaf(long("formatter-enabled"), argument("true|false"), optional)]
332341
formatter_enabled: Option<FormatterEnabled>,
333-
/// Allow to enable or disable the linter check.
342+
/// Allow enabling or disable the linter check.
334343
#[bpaf(long("linter-enabled"), argument("true|false"), optional)]
335344
linter_enabled: Option<LinterEnabled>,
336345

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

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

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

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

@@ -502,7 +514,7 @@ pub enum BiomeCommand {
502514

503515
#[bpaf(command("__run_server"), hide)]
504516
RunServer {
505-
/// Allows to change the prefix applied to the file name of the logs.
517+
/// Allows changing the prefix applied to the file name of the logs.
506518
#[bpaf(
507519
env("BIOME_LOG_PREFIX_NAME"),
508520
long("log-prefix-name"),
@@ -512,7 +524,7 @@ pub enum BiomeCommand {
512524
display_fallback
513525
)]
514526
log_prefix_name: String,
515-
/// Allows to change the folder where logs are stored.
527+
/// Allows changing the folder where logs are stored.
516528
#[bpaf(
517529
env("BIOME_LOG_PATH"),
518530
long("log-path"),

crates/biome_cli/tests/cases/assist.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,50 @@ fn assist_emit_diagnostic_and_blocks() {
9393
));
9494
}
9595

96+
#[test]
97+
fn assist_emit_diagnostic_and_blocks_ci() {
98+
let mut fs = MemoryFileSystem::default();
99+
let mut console = BufferConsole::default();
100+
101+
let config = Utf8Path::new("biome.json");
102+
fs.insert(
103+
config.into(),
104+
r#"{
105+
"assist": {
106+
"enabled": true,
107+
"actions": {
108+
"source": {
109+
"useSortedKeys": "on"
110+
}
111+
}
112+
},
113+
"formatter": { "enabled": false }
114+
}"#
115+
.as_bytes(),
116+
);
117+
let file = Utf8Path::new("file.json");
118+
fs.insert(
119+
file.into(),
120+
r#"{ "zod": true, "lorem": "ipsum", "foo": "bar" }"#.as_bytes(),
121+
);
122+
123+
let (fs, result) = run_cli(
124+
fs,
125+
&mut console,
126+
Args::from(["ci", file.as_str()].as_slice()),
127+
);
128+
129+
assert!(result.is_err(), "run_cli returned {result:?}");
130+
131+
assert_cli_snapshot(SnapshotPayload::new(
132+
module_path!(),
133+
"assist_emit_diagnostic_and_blocks_ci",
134+
fs,
135+
console,
136+
result,
137+
));
138+
}
139+
96140
#[test]
97141
fn assist_writes() {
98142
let mut fs = MemoryFileSystem::default();
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
---
2+
source: crates/biome_cli/tests/snap_test.rs
3+
expression: redactor(content)
4+
---
5+
## `biome.json`
6+
7+
```json
8+
{
9+
"assist": {
10+
"enabled": true,
11+
"actions": {
12+
"source": {
13+
"useSortedKeys": "on"
14+
}
15+
}
16+
},
17+
"formatter": { "enabled": false }
18+
}
19+
```
20+
21+
## `file.json`
22+
23+
```json
24+
{ "zod": true, "lorem": "ipsum", "foo": "bar" }
25+
```
26+
27+
# Termination Message
28+
29+
```block
30+
ci ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
31+
32+
× Some errors were emitted while running checks.
33+
34+
35+
36+
```
37+
38+
# Emitted Messages
39+
40+
```block
41+
file.json:1:1 assist/source/useSortedKeys FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
42+
43+
× The keys are not sorted.
44+
45+
> 1 │ { "zod": true, "lorem": "ipsum", "foo": "bar" }
46+
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
47+
48+
i Safe fix: They keys of the current object can be sorted.
49+
50+
- {·"zod"true"lorem""ipsum""foo""bar"·}
51+
+ {·"foo""bar"·,"lorem""ipsum","zod"true·}
52+
53+
54+
```
55+
56+
```block
57+
Checked 1 file in <TIME>. No fixes applied.
58+
Found 1 error.
59+
```

crates/biome_cli/tests/snapshots/main_cases_reporter_github/reports_diagnostics_github_ci_command.snap

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,12 @@ let f;
3636
ci ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
3737
3838
× Some errors were emitted while running checks.
39-
4039
4140
42-
```
43-
44-
# Emitted Messages
4541
46-
```block
47-
::notice title=assist/source/organizeImports,file=index.ts,line=1,endLine=1,col=1,endColumn=21::The imports and exports are not sorted.
4842
```
4943

50-
```block
51-
::notice title=assist/source/organizeImports,file=main.ts,line=1,endLine=1,col=1,endColumn=21::The imports and exports are not sorted.
52-
```
44+
# Emitted Messages
5345

5446
```block
5547
::warning title=lint/correctness/noUnusedImports,file=index.ts,line=1,endLine=1,col=8,endColumn=12::This import is unused.
@@ -83,6 +75,10 @@ ci ━━━━━━━━━━━━━━━━━━━━━━━━━
8375
::warning title=lint/correctness/noUnusedVariables,file=main.ts,line=9,endLine=9,col=7,endColumn=8::This variable is unused.
8476
```
8577

78+
```block
79+
::error title=assist/source/organizeImports,file=index.ts,line=1,endLine=1,col=1,endColumn=21::The imports and exports are not sorted.
80+
```
81+
8682
```block
8783
::error title=lint/suspicious/noDoubleEquals,file=index.ts,line=4,endLine=4,col=3,endColumn=5::Using == may be unsafe if you are relying on type coercion.
8884
```
@@ -111,6 +107,10 @@ ci ━━━━━━━━━━━━━━━━━━━━━━━━━
111107
::error title=format,file=index.ts,line=1,endLine=1,col=2,endColumn=2::File content differs from formatting output
112108
```
113109

110+
```block
111+
::error title=assist/source/organizeImports,file=main.ts,line=1,endLine=1,col=1,endColumn=21::The imports and exports are not sorted.
112+
```
113+
114114
```block
115115
::error title=lint/suspicious/noDoubleEquals,file=main.ts,line=4,endLine=4,col=3,endColumn=5::Using == may be unsafe if you are relying on type coercion.
116116
```

0 commit comments

Comments
 (0)