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

Merged
merged 67 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
62e46bc
WIP
anthonyshew Sep 20, 2024
9c50af1
WIP
anthonyshew Sep 20, 2024
a87006b
WIP
anthonyshew Sep 20, 2024
a39718d
WIP
anthonyshew Sep 20, 2024
cf0b9c0
WIP
anthonyshew Sep 22, 2024
02115cc
WIP
anthonyshew Sep 23, 2024
3b613f0
WIP
anthonyshew Sep 23, 2024
2eb7cdc
WIP
anthonyshew Sep 23, 2024
c378a77
WIP
anthonyshew Sep 26, 2024
dd05b07
WIP
anthonyshew Sep 26, 2024
c28db57
WIP
anthonyshew Sep 26, 2024
0cedb3e
WIP
anthonyshew Sep 26, 2024
a797a87
WIP
anthonyshew Sep 26, 2024
f1707a4
WIP
anthonyshew Sep 29, 2024
046e120
WIP
anthonyshew Sep 29, 2024
8bb572f
WIP
anthonyshew Sep 29, 2024
09889d0
WIP
anthonyshew Sep 29, 2024
25af91c
WIP
anthonyshew Sep 29, 2024
3611db0
WIP
anthonyshew Sep 29, 2024
6c6431b
WIP
anthonyshew Sep 29, 2024
8ddedf4
WIP
anthonyshew Sep 30, 2024
35e2145
WIP
anthonyshew Oct 2, 2024
86560e9
WIP
anthonyshew Oct 2, 2024
1b44843
WIP
anthonyshew Oct 2, 2024
88bfa71
WIP
anthonyshew Oct 2, 2024
f754916
WIP
anthonyshew Oct 2, 2024
0e1a789
WIP
anthonyshew Oct 2, 2024
e6b406d
WIP
anthonyshew Oct 2, 2024
cc81046
WIP
anthonyshew Oct 2, 2024
071d024
WIP
anthonyshew Oct 2, 2024
e43e9af
WIP
anthonyshew Oct 2, 2024
de33eab
Merge branch 'main' of https://github.com/anthonyshew/biome into shew…
anthonyshew Oct 2, 2024
3030687
WIP
anthonyshew Oct 2, 2024
f19cee6
Fix codegen.
anthonyshew Oct 2, 2024
2838190
WIP
anthonyshew Oct 2, 2024
82fd461
Update crates/biome_cli/src/commands/mod.rs
anthonyshew Oct 2, 2024
616b5da
WIP
anthonyshew Oct 2, 2024
1dfc0dc
Tests pass and behavior looks correct here. Write some more tests.
anthonyshew Oct 2, 2024
704cc59
Cleanup.
anthonyshew Oct 2, 2024
143db55
Wrote some tests.
anthonyshew Oct 2, 2024
063cb77
Fix codegen.
anthonyshew Oct 2, 2024
e5424b0
Reset codegen.
anthonyshew Oct 3, 2024
358bb87
codegen pls
anthonyshew Oct 3, 2024
66c9e9f
codegen pls
anthonyshew Oct 3, 2024
df889ec
WIP
anthonyshew Oct 3, 2024
497abd8
WIP
anthonyshew Oct 3, 2024
b870607
WIP
anthonyshew Oct 3, 2024
4ba4097
WIP
anthonyshew Oct 3, 2024
0aa9783
Fix JS API.
anthonyshew Oct 3, 2024
d5d8768
Merge branch 'main' into shew-d3bfe
anthonyshew Oct 3, 2024
23eaae2
Update crates/biome_cli/src/commands/mod.rs
anthonyshew Oct 5, 2024
f205f49
Update crates/biome_service/src/file_handlers/json.rs
anthonyshew Oct 5, 2024
50d5d17
Update crates/biome_service/src/file_handlers/graphql.rs
anthonyshew Oct 5, 2024
c143abd
Update crates/biome_service/src/file_handlers/css.rs
anthonyshew Oct 5, 2024
adeeb02
Fixes from review.
anthonyshew Oct 5, 2024
b497bd6
Merge branch 'shew-d3bfe' of https://github.com/anthonyshew/biome int…
anthonyshew Oct 5, 2024
6cd1584
Format.
anthonyshew Oct 5, 2024
9e8285f
Undo codegen since option is no longer there.
anthonyshew Oct 5, 2024
f6ce7b6
Merge branch 'main' into shew-d3bfe
anthonyshew Oct 5, 2024
5638e9a
Fix codegen?
anthonyshew Oct 5, 2024
e39b50a
Merge branch 'shew-d3bfe' of https://github.com/anthonyshew/biome int…
anthonyshew Oct 5, 2024
497a7e1
WIP
anthonyshew Oct 5, 2024
eaeebd4
WIP
anthonyshew Oct 5, 2024
aa121eb
WIP
anthonyshew Oct 5, 2024
45c26f4
WIP
anthonyshew Oct 5, 2024
b2a4ba3
Update snapshot.
anthonyshew Oct 5, 2024
0ccd3d0
Fix merge conflicts.
anthonyshew Oct 17, 2024
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
6 changes: 6 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,8 @@ pub(crate) struct CheckCommandPayload {
pub(crate) apply: bool,
pub(crate) apply_unsafe: bool,
pub(crate) write: bool,
pub(crate) suppress: bool,
pub(crate) suppress_reason: Option<String>,
pub(crate) fix: bool,
pub(crate) unsafe_: bool,
pub(crate) cli_options: CliOptions,
Expand All @@ -52,6 +54,8 @@ pub(crate) fn check(
apply,
apply_unsafe,
write,
suppress,
suppress_reason,
fix,
unsafe_,
cli_options,
Expand All @@ -73,6 +77,8 @@ pub(crate) fn check(
apply,
apply_unsafe,
write,
suppress,
suppress_reason,
fix,
unsafe_,
},
Expand Down
6 changes: 6 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,8 @@ pub(crate) struct FormatCommandPayload {
pub(crate) files_configuration: Option<PartialFilesConfiguration>,
pub(crate) stdin_file_path: Option<String>,
pub(crate) write: bool,
pub(crate) suppress: bool,
pub(crate) suppress_reason: Option<String>,
pub(crate) fix: bool,
pub(crate) cli_options: CliOptions,
pub(crate) paths: Vec<OsString>,
Expand All @@ -55,6 +57,8 @@ pub(crate) fn format(
stdin_file_path,
files_configuration,
write,
suppress,
suppress_reason,
fix,
mut json_formatter,
css_formatter,
Expand All @@ -69,6 +73,8 @@ pub(crate) fn format(
apply: false,
apply_unsafe: false,
write,
suppress,
suppress_reason,
fix,
unsafe_: false,
})?;
Expand Down
7 changes: 7 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,8 @@ pub(crate) struct LintCommandPayload {
pub(crate) apply: bool,
pub(crate) apply_unsafe: bool,
pub(crate) write: bool,
pub(crate) suppress: bool,
pub(crate) suppress_reason: Option<String>,
pub(crate) fix: bool,
pub(crate) unsafe_: bool,
pub(crate) cli_options: CliOptions,
Expand All @@ -53,6 +55,8 @@ pub(crate) fn lint(session: CliSession, payload: LintCommandPayload) -> Result<(
apply,
apply_unsafe,
write,
suppress,
suppress_reason,
fix,
unsafe_,
cli_options,
Expand All @@ -78,6 +82,8 @@ pub(crate) fn lint(session: CliSession, payload: LintCommandPayload) -> Result<(
apply,
apply_unsafe,
write,
suppress,
suppress_reason,
fix,
unsafe_,
},
Expand Down Expand Up @@ -181,6 +187,7 @@ pub(crate) fn lint(session: CliSession, payload: LintCommandPayload) -> Result<(
only,
skip,
vcs_targeted: VcsTargeted { staged, changed },
suppress,
})
.set_report(&cli_options),
session,
Expand Down
4 changes: 4 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,8 @@ pub(crate) fn migrate(
session: CliSession,
cli_options: CliOptions,
write: bool,
suppress: bool,
suppress_reason: Option<String>,
fix: bool,
sub_command: Option<MigrateSubCommand>,
) -> Result<(), CliDiagnostic> {
Expand All @@ -29,6 +31,8 @@ pub(crate) fn migrate(
apply: false,
apply_unsafe: false,
write,
suppress,
suppress_reason,
fix,
unsafe_: false,
})?;
Expand Down
59 changes: 57 additions & 2 deletions crates/biome_cli/src/commands/mod.rs
anthonyshew marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use crate::changed::{get_changed_files, get_staged_files};
use crate::cli_options::{cli_options, CliOptions, CliReporter, ColorsArg};
use crate::diagnostics::{DeprecatedArgument, DeprecatedConfigurationFile};
use crate::diagnostics::{
DeprecatedArgument, DeprecatedConfigurationFile, IncompatibleEndConfiguration,
};
use crate::execute::Stdin;
use crate::logging::LoggingKind;
use crate::{CliDiagnostic, LoggingLevel, VERSION};
Expand Down Expand Up @@ -105,6 +107,13 @@ pub enum BiomeCommand {
#[bpaf(long("write"), switch)]
write: bool,

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

#[bpaf(long("suppress-reason"))]
suppress_reason: Option<String>,

/// Allow to do unsafe fixes, should be used with `--write` or `--fix`
#[bpaf(long("unsafe"), switch)]
unsafe_: bool,
Expand Down Expand Up @@ -183,6 +192,12 @@ pub enum BiomeCommand {
#[bpaf(long("write"), switch)]
write: bool,

#[bpaf(long("suppress"))]
suppress: bool,

#[bpaf(long("suppress-reason"))]
suppress_reason: Option<String>,

/// Allow to do unsafe fixes, should be used with `--write` or `--fix`
#[bpaf(long("unsafe"), switch)]
unsafe_: bool,
Expand Down Expand Up @@ -299,6 +314,14 @@ pub enum BiomeCommand {
#[bpaf(long("write"), switch)]
write: bool,

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

/// Writes inline biome-ignore comments to ignore existing diagnostics
#[bpaf(long("suppress-reason"))]
suppress_reason: Option<String>,

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

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

#[bpaf(long("suppress-reason"))]
suppress_reason: Option<String>,

/// Alias of `--write`, writes the new configuration file to disk
#[bpaf(long("fix"), switch, hide_usage)]
fix: bool,
Expand Down Expand Up @@ -724,6 +754,8 @@ pub(crate) struct FixFileModeOptions {
apply: bool,
apply_unsafe: bool,
write: bool,
suppress: bool,
suppress_reason: Option<String>,
fix: bool,
unsafe_: bool,
}
Expand All @@ -740,6 +772,8 @@ pub(crate) fn determine_fix_file_mode(
apply_unsafe,
write,
fix,
suppress,
ref suppress_reason,
unsafe_,
} = options;

Expand All @@ -764,6 +798,8 @@ pub(crate) fn determine_fix_file_mode(
Ok(Some(FixFileMode::SafeAndUnsafeFixes))
} else if safe_fixes {
Ok(Some(FixFileMode::SafeFixes))
} else if suppress {
Ok(Some(FixFileMode::ApplySuppressions))
} else {
Ok(None)
}
Expand All @@ -775,6 +811,8 @@ fn check_fix_incompatible_arguments(options: FixFileModeOptions) -> Result<(), C
apply,
apply_unsafe,
write,
suppress,
suppress_reason,
fix,
unsafe_,
} = options;
Expand All @@ -800,6 +838,19 @@ fn check_fix_incompatible_arguments(options: FixFileModeOptions) -> Result<(), C
));
} else if write && fix {
return Err(CliDiagnostic::incompatible_arguments("--write", "--fix"));
} else if suppress && write {
return Err(CliDiagnostic::incompatible_arguments(
"--suppress",
"--write",
));
} else if suppress && fix {
return Err(CliDiagnostic::incompatible_arguments("--suppress", "--fix"));
} else if !suppress && suppress_reason.is_some() {
return Err(CliDiagnostic::IncompatibleEndConfiguration(
IncompatibleEndConfiguration {
reason: "--suppress-reason must be used with --suppress".to_string(),
},
));
}
Ok(())
}
Expand All @@ -812,7 +863,7 @@ mod tests {

#[test]
fn incompatible_arguments() {
for (apply, apply_unsafe, write, fix, unsafe_) in [
for (apply, apply_unsafe, write, suppress, fix, unsafe_) in [
(true, true, false, false, false), // --apply --apply-unsafe
(true, false, true, false, false), // --apply --write
(true, false, false, true, false), // --apply --fix
Expand All @@ -825,6 +876,7 @@ mod tests {
apply,
apply_unsafe,
write,
suppress,
fix,
unsafe_
})
Expand All @@ -847,6 +899,7 @@ mod tests {
apply,
apply_unsafe,
write,
suppress,
fix,
unsafe_
},
Expand All @@ -873,6 +926,7 @@ mod tests {
apply,
apply_unsafe,
write,
suppress,
fix,
unsafe_
},
Expand All @@ -895,6 +949,7 @@ mod tests {
apply,
apply_unsafe,
write,
suppress,
fix,
unsafe_
},
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 @@ -223,7 +223,7 @@ pub struct ServerNotRunning;
)
)]
pub struct IncompatibleEndConfiguration {
reason: String,
pub reason: String,
}

#[derive(Debug, Diagnostic)]
Expand Down
12 changes: 12 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,
suppress: bool,
},
/// This mode is enabled when running the command `biome ci`
CI {
Expand Down Expand Up @@ -304,6 +305,17 @@ impl Execution {
}
}

pub(crate) fn as_write_suppressions_mode(&self) -> Option<&bool> {
match &self.traversal_mode {
TraversalMode::Lint { suppress, .. } => Some(suppress),
anthonyshew marked this conversation as resolved.
Show resolved Hide resolved
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,
suppress: 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
Loading
Loading