Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: flag to suppress existing diagnostics #4008

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from
Draft
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
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 @@ -28,6 +28,7 @@ pub(crate) struct CheckCommandPayload {
pub(crate) apply: bool,
pub(crate) apply_unsafe: bool,
pub(crate) write: bool,
pub(crate) write_suppressions: bool,
pub(crate) fix: bool,
pub(crate) unsafe_: bool,
pub(crate) cli_options: CliOptions,
Expand All @@ -52,6 +53,7 @@ pub(crate) fn check(
apply,
apply_unsafe,
write,
write_suppressions,
fix,
unsafe_,
cli_options,
Expand All @@ -73,6 +75,7 @@ pub(crate) fn check(
apply,
apply_unsafe,
write,
write_suppressions,
fix,
unsafe_,
},
Expand Down
3 changes: 3 additions & 0 deletions crates/biome_cli/src/commands/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pub(crate) struct FormatCommandPayload {
pub(crate) files_configuration: Option<PartialFilesConfiguration>,
pub(crate) stdin_file_path: Option<String>,
pub(crate) write: bool,
pub(crate) write_suppressions: bool,
pub(crate) fix: bool,
pub(crate) cli_options: CliOptions,
pub(crate) paths: Vec<OsString>,
Expand All @@ -55,6 +56,7 @@ pub(crate) fn format(
stdin_file_path,
files_configuration,
write,
write_suppressions,
fix,
mut json_formatter,
css_formatter,
Expand All @@ -69,6 +71,7 @@ pub(crate) fn format(
apply: false,
apply_unsafe: false,
write,
write_suppressions,
fix,
unsafe_: false,
})?;
Expand Down
4 changes: 4 additions & 0 deletions crates/biome_cli/src/commands/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub(crate) struct LintCommandPayload {
pub(crate) apply: bool,
pub(crate) apply_unsafe: bool,
pub(crate) write: bool,
pub(crate) write_suppressions: bool,
pub(crate) fix: bool,
pub(crate) unsafe_: bool,
pub(crate) cli_options: CliOptions,
Expand Down Expand Up @@ -70,6 +71,7 @@ pub(crate) fn lint(session: CliSession, payload: LintCommandPayload) -> Result<(
css_linter,
json_linter,
graphql_linter,
write_suppressions,
} = payload;
setup_cli_subscriber(cli_options.log_level, cli_options.log_kind);

Expand All @@ -78,6 +80,7 @@ pub(crate) fn lint(session: CliSession, payload: LintCommandPayload) -> Result<(
apply,
apply_unsafe,
write,
write_suppressions,
fix,
unsafe_,
},
Expand Down Expand Up @@ -181,6 +184,7 @@ pub(crate) fn lint(session: CliSession, payload: LintCommandPayload) -> Result<(
only,
skip,
vcs_targeted: VcsTargeted { staged, changed },
write_suppressions,
})
.set_report(&cli_options),
session,
Expand Down
2 changes: 2 additions & 0 deletions crates/biome_cli/src/commands/migrate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub(crate) fn migrate(
session: CliSession,
cli_options: CliOptions,
write: bool,
write_suppressions: bool,
fix: bool,
sub_command: Option<MigrateSubCommand>,
) -> Result<(), CliDiagnostic> {
Expand All @@ -29,6 +30,7 @@ pub(crate) fn migrate(
apply: false,
apply_unsafe: false,
write,
write_suppressions,
fix,
unsafe_: false,
})?;
Expand Down
31 changes: 31 additions & 0 deletions crates/biome_cli/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ pub enum BiomeCommand {
#[bpaf(long("write"), switch)]
write: bool,

/// Writes inline biome-ignore comments to ignore existing diagnostics
#[bpaf(long("write"), switch)]
write_suppressions: bool,

/// Allow to do unsafe fixes, should be used with `--write` or `--fix`
#[bpaf(long("unsafe"), switch)]
unsafe_: bool,
Expand Down Expand Up @@ -220,6 +224,9 @@ pub enum BiomeCommand {
#[bpaf(external(partial_graphql_linter), optional, hide_usage, hide)]
graphql_linter: Option<PartialGraphqlLinter>,

#[bpaf(long("write-suppressions"))]
write_suppressions: bool,

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

Expand Down Expand Up @@ -298,6 +305,7 @@ pub enum BiomeCommand {
/// Writes formatted files to file system.
#[bpaf(long("write"), switch)]
write: bool,
write_suppressions: bool,

/// Alias of `--write`, writes formatted files to file system.
#[bpaf(long("fix"), switch, hide_usage)]
Expand Down Expand Up @@ -408,6 +416,10 @@ pub enum BiomeCommand {
#[bpaf(long("write"), switch)]
write: bool,

/// Writes inline biome-ignore comments to ignore existing diagnostics
#[bpaf(long("write"), switch)]
write_suppressions: bool,

/// Alias of `--write`, writes the new configuration file to disk
#[bpaf(long("fix"), switch, hide_usage)]
fix: bool,
Expand Down Expand Up @@ -724,6 +736,7 @@ pub(crate) struct FixFileModeOptions {
apply: bool,
apply_unsafe: bool,
write: bool,
write_suppressions: bool,
fix: bool,
unsafe_: bool,
}
Expand All @@ -740,6 +753,7 @@ pub(crate) fn determine_fix_file_mode(
apply_unsafe,
write,
fix,
write_suppressions,
unsafe_,
} = options;

Expand All @@ -764,6 +778,8 @@ pub(crate) fn determine_fix_file_mode(
Ok(Some(FixFileMode::SafeAndUnsafeFixes))
} else if safe_fixes {
Ok(Some(FixFileMode::SafeFixes))
} else if write_suppressions {
Ok(Some(FixFileMode::ApplySuppressions))
} else {
Ok(None)
}
Expand All @@ -775,6 +791,7 @@ fn check_fix_incompatible_arguments(options: FixFileModeOptions) -> Result<(), C
apply,
apply_unsafe,
write,
write_suppressions,
fix,
unsafe_,
} = options;
Expand All @@ -800,6 +817,16 @@ fn check_fix_incompatible_arguments(options: FixFileModeOptions) -> Result<(), C
));
} else if write && fix {
return Err(CliDiagnostic::incompatible_arguments("--write", "--fix"));
} else if write_suppressions && write {
return Err(CliDiagnostic::incompatible_arguments(
"--write-suppressions",
"--write",
));
} else if write_suppressions && fix {
return Err(CliDiagnostic::incompatible_arguments(
"--write-suppressions",
"--fix",
));
}
Ok(())
}
Expand All @@ -825,6 +852,7 @@ mod tests {
apply,
apply_unsafe,
write,
write_suppressions,
fix,
unsafe_
})
Expand All @@ -847,6 +875,7 @@ mod tests {
apply,
apply_unsafe,
write,
write_suppressions,
fix,
unsafe_
},
Expand All @@ -873,6 +902,7 @@ mod tests {
apply,
apply_unsafe,
write,
write_suppressions,
fix,
unsafe_
},
Expand All @@ -895,6 +925,7 @@ mod tests {
apply,
apply_unsafe,
write,
write_suppressions,
fix,
unsafe_
},
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 @@ -151,6 +151,7 @@ pub enum TraversalMode {
skip: Vec<RuleSelector>,
/// A flag to know vcs integrated options such as `--staged` or `--changed` are enabled
vcs_targeted: VcsTargeted,
write_suppressions: bool,
},
/// This mode is enabled when running the command `biome ci`
CI {
Expand Down Expand Up @@ -304,6 +305,19 @@ impl Execution {
}
}

pub(crate) fn as_write_suppressions_mode(&self) -> Option<&bool> {
match &self.traversal_mode {
TraversalMode::Lint {
write_suppressions, ..
} => Some(write_suppressions),
TraversalMode::Check { .. }
| TraversalMode::Format { .. }
| TraversalMode::CI { .. }
| TraversalMode::Migrate { .. }
| TraversalMode::Search { .. } => None,
}
}

pub(crate) fn as_diagnostic_category(&self) -> &'static Category {
match self.traversal_mode {
TraversalMode::Check { .. } => category!("check"),
Expand Down
1 change: 1 addition & 0 deletions crates/biome_cli/src/execute/process_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ impl<'ctx, 'app> Deref for SharedTraversalOptions<'ctx, 'app> {
/// content of the file and emit a diff or write the new content to the disk if
/// write mode is enabled
pub(crate) fn process_file(ctx: &TraversalOptions, biome_path: &BiomePath) -> FileResult {
ctx.execution.as_write_suppressions_mode();
tracing::trace_span!("process_file", path = ?biome_path).in_scope(move || {
let file_features = ctx
.workspace
Expand Down
1 change: 1 addition & 0 deletions crates/biome_cli/src/execute/process_file/assists.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub(crate) fn assists_with_guard<'ctx>(
.guard()
.fix_file(
FixFileMode::SafeFixes,
ctx.execution.as_write_suppressions_mode().is_some(),
false,
RuleCategoriesBuilder::default().with_action().build(),
only.clone(),
Expand Down
1 change: 1 addition & 0 deletions crates/biome_cli/src/execute/process_file/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ pub(crate) fn lint_with_guard<'ctx>(
.guard()
.fix_file(
*fix_mode,
ctx.execution.as_write_suppressions_mode().is_some(),
false,
RuleCategoriesBuilder::default()
.with_syntax()
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 @@ -117,6 +117,7 @@ pub(crate) fn run<'a>(
if file_features.supports_lint() {
let fix_file_result = workspace.fix_file(FixFileParams {
fix_file_mode: *fix_file_mode,
write_suppressions: mode.as_write_suppressions_mode().is_some(),
path: biome_path.clone(),
should_format: mode.is_check() && file_features.supports_format(),
only: only.clone(),
Expand Down
16 changes: 15 additions & 1 deletion crates/biome_cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ impl<'app> CliSession<'app> {
apply,
apply_unsafe,
write,
write_suppressions,
fix,
unsafe_,
cli_options,
Expand All @@ -109,6 +110,7 @@ impl<'app> CliSession<'app> {
apply_unsafe,
apply,
write,
write_suppressions,
fix,
unsafe_,
cli_options,
Expand Down Expand Up @@ -145,6 +147,7 @@ impl<'app> CliSession<'app> {
javascript_linter,
json_linter,
graphql_linter,
write_suppressions,
} => commands::lint::lint(
self,
LintCommandPayload {
Expand All @@ -168,6 +171,7 @@ impl<'app> CliSession<'app> {
javascript_linter,
json_linter,
graphql_linter,
write_suppressions,
},
),
BiomeCommand::Ci {
Expand Down Expand Up @@ -199,6 +203,7 @@ impl<'app> CliSession<'app> {
formatter_configuration,
stdin_file_path,
write,
write_suppressions,
fix,
cli_options,
paths,
Expand All @@ -217,6 +222,7 @@ impl<'app> CliSession<'app> {
formatter_configuration,
stdin_file_path,
write,
write_suppressions,
fix,
cli_options,
paths,
Expand All @@ -241,9 +247,17 @@ impl<'app> CliSession<'app> {
BiomeCommand::Migrate {
cli_options,
write,
write_suppressions,
fix,
sub_command,
} => commands::migrate::migrate(self, cli_options, write, fix, sub_command),
} => commands::migrate::migrate(
self,
cli_options,
write,
write_suppressions,
fix,
sub_command,
),
BiomeCommand::Search {
cli_options,
files_configuration,
Expand Down
1 change: 1 addition & 0 deletions crates/biome_lsp/src/handlers/analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ fn fix_all(
let fixed = session.workspace.fix_file(FixFileParams {
path: biome_path,
fix_file_mode: FixFileMode::SafeFixes,
write_suppressions: false,
should_format,
only: vec![],
skip: vec![],
Expand Down
3 changes: 3 additions & 0 deletions crates/biome_service/src/file_handlers/css.rs
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,9 @@ pub(crate) fn fix_all(params: FixAllParams) -> Result<FixFileResult, WorkspaceEr
return ControlFlow::Break(action);
}
}
FixFileMode::ApplySuppressions => {
println!("No-op'ing in CSS.")
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions crates/biome_service/src/file_handlers/graphql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,9 @@ pub(crate) fn fix_all(params: FixAllParams) -> Result<FixFileResult, WorkspaceEr
return ControlFlow::Break(action);
}
}
FixFileMode::ApplySuppressions => {
println!("No-op'ing in JSON.")
}
}
}

Expand Down
8 changes: 5 additions & 3 deletions crates/biome_service/src/file_handlers/javascript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -659,12 +659,14 @@ pub(crate) fn fix_all(params: FixAllParams) -> Result<FixFileResult, WorkspaceEr
}

for action in signal.actions() {
// suppression actions should not be part of the fixes (safe or suggested)
if action.is_suppression() {
continue;
if action.is_suppression() && params.write_suppressions {
return ControlFlow::Break(action);
}

match params.fix_file_mode {
FixFileMode::ApplySuppressions => {
// No-op, handled above
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hm, this isn't great.

}
FixFileMode::SafeFixes => {
if action.applicability == Applicability::MaybeIncorrect {
skipped_suggested_fixes += 1;
Expand Down
Loading
Loading