Skip to content

Commit

Permalink
It works!
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonyshew committed Oct 26, 2024
1 parent c6a105e commit 63392b3
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
3 changes: 2 additions & 1 deletion crates/biome_cli/src/execute/process_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,11 @@ pub(crate) fn process_file(ctx: &TraversalOptions, biome_path: &BiomePath) -> Fi
match ctx.execution.traversal_mode {
TraversalMode::Lint {
ref suppression_reason,
suppress,
..
} => {
// the unsupported case should be handled already at this point
lint(shared_context, biome_path, suppression_reason)
lint(shared_context, biome_path, suppress, suppression_reason)
}
TraversalMode::Format { .. } => {
// the unsupported case should be handled already at this point
Expand Down
2 changes: 1 addition & 1 deletion crates/biome_cli/src/execute/process_file/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub(crate) fn check_file<'ctx>(
tracing::info_span!("Process check", path =? workspace_file.path.display()).in_scope(
move || {
if file_features.supports_lint() {
let lint_result = lint_with_guard(ctx, &mut workspace_file, None);
let lint_result = lint_with_guard(ctx, &mut workspace_file, false, None);
match lint_result {
Ok(status) => {
if status.is_changed() {
Expand Down
17 changes: 15 additions & 2 deletions crates/biome_cli/src/execute/process_file/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,22 @@ use std::sync::atomic::Ordering;
pub(crate) fn lint<'ctx>(
ctx: &'ctx SharedTraversalOptions<'ctx, '_>,
path: &Path,
suppress: bool,
suppression_reason: &Option<String>,
) -> FileResult {
let mut workspace_file = WorkspaceFile::new(ctx, path)?;
lint_with_guard(ctx, &mut workspace_file, suppression_reason.clone())
lint_with_guard(
ctx,
&mut workspace_file,
suppress,
suppression_reason.clone(),
)
}

pub(crate) fn lint_with_guard<'ctx>(
ctx: &'ctx SharedTraversalOptions<'ctx, '_>,
workspace_file: &mut WorkspaceFile,
suppress: bool,
suppression_reason: Option<String>,
) -> FileResult {
tracing::info_span!("Processes linting", path =? workspace_file.path.display()).in_scope(
Expand All @@ -36,6 +43,12 @@ pub(crate) fn lint_with_guard<'ctx>(
(Vec::new(), Vec::new())
};
if let Some(fix_mode) = ctx.execution.as_fix_file_mode() {
let suppression_explanation = if suppress && suppression_reason.is_none() {
"Ignored using `--suppress`".to_string()
} else {
suppression_reason.unwrap_or("<explanation>".to_string())
};

let fix_result = workspace_file
.guard()
.fix_file(
Expand All @@ -47,7 +60,7 @@ pub(crate) fn lint_with_guard<'ctx>(
.build(),
only.clone(),
skip.clone(),
Some(suppression_reason.unwrap_or("<explanation>".to_string())),
Some(suppression_explanation),
)
.with_file_path_and_code(
workspace_file.path.display().to_string(),
Expand Down
4 changes: 2 additions & 2 deletions crates/biome_graphql_analyze/src/suppression_action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl SuppressionAction for GraphqlSuppressionAction {
mutation: &mut BatchMutation<Self::Language>,
apply_suppression: ApplySuppression<Self::Language>,
suppression_text: &str,
_suppression_reason: String,
suppression_reason: String,
) {
let ApplySuppression {
token_to_apply_suppression,
Expand All @@ -53,7 +53,7 @@ impl SuppressionAction for GraphqlSuppressionAction {
.filter(|trivia| trivia.is_whitespace())
.collect();

let suppression_comment = format!("# {}: <explanation>", suppression_text);
let suppression_comment = format!("# {}: {}", suppression_text, suppression_reason);
let suppression_comment = suppression_comment.as_str();
let trivia = [
(TriviaPieceKind::SingleLineComment, suppression_comment),
Expand Down

0 comments on commit 63392b3

Please sign in to comment.