Skip to content
Closed
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
5 changes: 5 additions & 0 deletions .changeset/busy-olives-hang.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@biomejs/biome": patch
---

Fixed #7772: `--fix` now respects `--diagnostic-level`
3 changes: 3 additions & 0 deletions crates/biome_cli/src/commands/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use biome_configuration::formatter::FormatterEnabled;
use biome_configuration::{Configuration, FormatterConfiguration, LinterConfiguration};
use biome_console::Console;
use biome_deserialize::Merge;
use biome_diagnostics::Severity;
use biome_fs::FileSystem;
use biome_service::{Workspace, WorkspaceError, configuration::LoadedConfiguration};
use std::ffi::OsString;
Expand All @@ -26,6 +27,7 @@ pub(crate) struct CheckCommandPayload {
pub(crate) staged: bool,
pub(crate) changed: bool,
pub(crate) since: Option<String>,
pub(crate) fix_level: Severity,
}

impl LoadEditorConfig for CheckCommandPayload {
Expand Down Expand Up @@ -144,6 +146,7 @@ impl CommandRunner for CheckCommandPayload {
vcs_targeted: (self.staged, self.changed).into(),
enforce_assist: self.enforce_assist,
skip_parse_errors: cli_options.skip_parse_errors,
fix_level: self.fix_level,
})
.set_report(cli_options))
}
Expand Down
3 changes: 3 additions & 0 deletions crates/biome_cli/src/commands/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use biome_configuration::vcs::VcsConfiguration;
use biome_configuration::{Configuration, FilesConfiguration, LinterConfiguration};
use biome_console::Console;
use biome_deserialize::Merge;
use biome_diagnostics::Severity;
use biome_fs::FileSystem;
use biome_service::configuration::LoadedConfiguration;
use biome_service::{Workspace, WorkspaceError};
Expand All @@ -36,6 +37,7 @@ pub(crate) struct LintCommandPayload {
pub(crate) json_linter: Option<JsonLinterConfiguration>,
pub(crate) css_linter: Option<CssLinterConfiguration>,
pub(crate) graphql_linter: Option<GraphqlLinterConfiguration>,
pub(crate) fix_level: Severity,
}

impl CommandRunner for LintCommandPayload {
Expand Down Expand Up @@ -143,6 +145,7 @@ impl CommandRunner for LintCommandPayload {
suppress: self.suppress,
suppression_reason: self.suppression_reason.clone(),
skip_parse_errors: cli_options.skip_parse_errors,
fix_level: self.fix_level,
})
.set_report(cli_options))
}
Expand Down
18 changes: 18 additions & 0 deletions crates/biome_cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,15 @@ pub enum BiomeCommand {
#[bpaf(long("fix"), switch, hide_usage)]
fix: bool,

/// The level of diagnostics to fix. In order, from the lowest to the most important: info, warn, error. Passing `--fix-level=error` will cause Biome only to fix error-level diagnostics contain only errors.
#[bpaf(
long("fix-level"),
argument("info|warn|error"),
fallback(Severity::default()),
display_fallback
)]
fix_level: Severity,

/// Allow enabling or disabling the formatter check.
#[bpaf(
long("formatter-enabled"),
Expand Down Expand Up @@ -273,6 +282,15 @@ pub enum BiomeCommand {
/// Single file, single path or list of paths
#[bpaf(positional("PATH"), many)]
paths: Vec<OsString>,

/// The level of diagnostics to fix. In order, from the lowest to the most important: info, warn, error. Passing `--fix-level=error` will cause Biome only to fix error-level diagnostics contain only errors.
#[bpaf(
long("fix-level"),
argument("info|warn|error"),
fallback(Severity::default()),
display_fallback
)]
fix_level: Severity,
},
/// Run the formatter on a set of files.
#[bpaf(command)]
Expand Down
2 changes: 2 additions & 0 deletions crates/biome_cli/src/commands/scan_kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ mod tests {
suppress: false,
suppression_reason: None,
skip_parse_errors: false,
fix_level: biome_diagnostics::Severity::default(),
});

let root_dir = Utf8Path::new("/");
Expand Down Expand Up @@ -125,6 +126,7 @@ mod tests {
vcs_targeted: VcsTargeted::default(),
skip_parse_errors: false,
enforce_assist: true,
fix_level: biome_diagnostics::Severity::default(),
});

let config = Configuration {
Expand Down
14 changes: 14 additions & 0 deletions crates/biome_cli/src/execute/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ pub enum TraversalMode {

/// It skips parse errors
skip_parse_errors: bool,

/// The minimum level of diagnostics to fix
fix_level: biome_diagnostics::Severity,
},
/// This mode is enabled when running the command `biome lint`
Lint {
Expand Down Expand Up @@ -139,6 +142,9 @@ pub enum TraversalMode {

/// It skips parse errors
skip_parse_errors: bool,

/// The minimum level of diagnostics to fix
fix_level: biome_diagnostics::Severity,
},
/// This mode is enabled when running the command `biome ci`
CI {
Expand Down Expand Up @@ -510,6 +516,14 @@ impl Execution {
_ => false,
}
}

pub(crate) fn get_fix_level(&self) -> biome_diagnostics::Severity {
match &self.traversal_mode {
TraversalMode::Check { fix_level, .. } => *fix_level,
TraversalMode::Lint { fix_level, .. } => *fix_level,
_ => biome_diagnostics::Severity::default(),
}
}
}

/// Based on the [mode](TraversalMode), the function might launch a traversal of the file system
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ pub(crate) fn analyze_with_guard<'ctx>(
only.clone(),
skip.clone(),
Some(suppression_explanation.to_string()),
Some(ctx.fix_level),
)
.with_file_path_and_code(
workspace_file.path.to_string(),
Expand Down
1 change: 1 addition & 0 deletions crates/biome_cli/src/execute/std_in.rs
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ pub(crate) fn run<'a>(
suppression_reason: None,
enabled_rules: vec![],
rule_categories: rule_categories.build(),
fix_level: Some(mode.get_fix_level()),
})?;
let code = fix_file_result.code;
let output = match biome_path.extension() {
Expand Down
3 changes: 3 additions & 0 deletions crates/biome_cli/src/execute/traverse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ pub(crate) fn traverse(
skipped: &skipped,
messages: sender,
evaluated_paths: RwLock::default(),
fix_level: execution.get_fix_level(),
},
);
// wait for the main thread to finish
Expand Down Expand Up @@ -447,6 +448,8 @@ pub(crate) struct TraversalOptions<'ctx, 'app> {
pub(crate) messages: Sender<Message>,
/// List of paths that should be processed
pub(crate) evaluated_paths: RwLock<BTreeSet<BiomePath>>,
/// The minimum diagnostic level to fix
pub(crate) fix_level: biome_diagnostics::Severity,
}

impl TraversalOptions<'_, '_> {
Expand Down
4 changes: 4 additions & 0 deletions crates/biome_cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ impl<'app> CliSession<'app> {
staged,
changed,
since,
fix_level,
} => run_command(
self,
&cli_options,
Expand All @@ -108,6 +109,7 @@ impl<'app> CliSession<'app> {
staged,
changed,
since,
fix_level,
},
),
BiomeCommand::Lint {
Expand All @@ -131,6 +133,7 @@ impl<'app> CliSession<'app> {
javascript_linter,
json_linter,
graphql_linter,
fix_level,
} => run_command(
self,
&cli_options,
Expand All @@ -154,6 +157,7 @@ impl<'app> CliSession<'app> {
javascript_linter,
json_linter,
graphql_linter,
fix_level,
},
),
BiomeCommand::Ci {
Expand Down
Loading
Loading