Skip to content
Merged
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/tiny-dodos-ask.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@biomejs/biome": patch
---

Fixed an issue where some info diagnostics weren't tracked by the final summary.
60 changes: 0 additions & 60 deletions crates/biome_cli/examples/text_reporter.rs

This file was deleted.

2 changes: 1 addition & 1 deletion crates/biome_cli/src/cli_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::fmt::{Display, Formatter};
use std::str::FromStr;

/// Global options applied to all commands
#[derive(Debug, Clone, Bpaf)]
#[derive(Debug, Default, Clone, Bpaf)]
pub struct CliOptions {
/// Set the formatting mode for markup: "off" prints everything as plain text, "force" forces the formatting of markup using ANSI even if the console output is determined to be incompatible
#[bpaf(long("colors"), argument("off|force"))]
Expand Down
175 changes: 137 additions & 38 deletions crates/biome_cli/src/commands/check.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
use super::{FixFileModeOptions, LoadEditorConfig, determine_fix_file_mode};
use super::{FixFileModeOptions, determine_fix_file_mode, get_files_to_process_with_cli_options};
use crate::CliDiagnostic;
use crate::cli_options::CliOptions;
use crate::commands::{CommandRunner, get_files_to_process_with_cli_options};
use crate::{CliDiagnostic, Execution, TraversalMode};
use crate::runner::execution::{AnalyzerSelectors, Execution, VcsTargeted};
use crate::runner::impls::commands::traversal::{LoadEditorConfig, TraversalCommand};
use crate::runner::impls::executions::summary_verb::SummaryVerbExecution;
use crate::runner::impls::process_file::check::CheckProcessFile;
use biome_configuration::analyzer::LinterEnabled;
use biome_configuration::analyzer::assist::{AssistConfiguration, AssistEnabled};
use biome_configuration::css::CssParserConfiguration;
use biome_configuration::formatter::{FormatWithErrorsEnabled, FormatterEnabled};
use biome_configuration::json::JsonParserConfiguration;
use biome_configuration::{Configuration, FormatterConfiguration, LinterConfiguration};
use biome_console::Console;
use biome_console::{Console, MarkupBuf};
use biome_deserialize::Merge;
use biome_diagnostics::{Category, category};
use biome_fs::FileSystem;
use biome_service::workspace::{
FeatureKind, FeatureName, FeaturesBuilder, FeaturesSupported, FixFileMode, ScanKind,
SupportKind,
};
use biome_service::{Workspace, WorkspaceError};
use camino::Utf8PathBuf;
use std::ffi::OsString;
use std::time::Duration;

pub(crate) struct CheckCommandPayload {
pub(crate) write: bool,
Expand All @@ -34,6 +43,97 @@ pub(crate) struct CheckCommandPayload {
pub(crate) css_parser: Option<CssParserConfiguration>,
}

struct CheckExecution {
/// The type of fixes that should be applied when analyzing a file.
///
/// It's [None] if the `check` command is called without `--apply` or `--apply-suggested`
/// arguments.
fix_file_mode: Option<FixFileMode>,
/// An optional tuple.
/// 1. The virtual path to the file
/// 2. The content of the file
stdin_file_path: Option<String>,
/// A flag to know vcs integrated options such as `--staged` or `--changed` are enabled
vcs_targeted: VcsTargeted,

/// Whether assist diagnostics should be promoted to error, and fail the CLI
enforce_assist: bool,

/// It skips parse errors
skip_parse_errors: bool,
}

impl Execution for CheckExecution {
fn features(&self) -> FeatureName {
FeaturesBuilder::new()
.with_linter()
.with_formatter()
.with_assist()
.build()
}

fn can_handle(&self, features: FeaturesSupported) -> bool {
features.supports_lint() || features.supports_assist() || features.supports_format()
}

fn is_vcs_targeted(&self) -> bool {
self.vcs_targeted.changed || self.vcs_targeted.staged
}

fn supports_kind(&self, file_features: &FeaturesSupported) -> Option<SupportKind> {
file_features
.support_kind_if_not_enabled(FeatureKind::Lint)
.and(file_features.support_kind_if_not_enabled(FeatureKind::Format))
.and(file_features.support_kind_if_not_enabled(FeatureKind::Assist))
}

fn get_stdin_file_path(&self) -> Option<&str> {
self.stdin_file_path.as_deref()
}

fn is_check(&self) -> bool {
true
}

fn as_diagnostic_category(&self) -> &'static Category {
category!("check")
}

fn is_safe_fixes_enabled(&self) -> bool {
self.fix_file_mode
.is_some_and(|fix_mode| fix_mode == FixFileMode::SafeFixes)
}

fn is_safe_and_unsafe_fixes_enabled(&self) -> bool {
self.fix_file_mode
.is_some_and(|fix_mode| fix_mode == FixFileMode::SafeAndUnsafeFixes)
}

fn as_fix_file_mode(&self) -> Option<FixFileMode> {
self.fix_file_mode
}

fn should_skip_parse_errors(&self) -> bool {
self.skip_parse_errors
}

fn requires_write_access(&self) -> bool {
self.fix_file_mode.is_some()
}

fn analyzer_selectors(&self) -> AnalyzerSelectors {
AnalyzerSelectors::default()
}

fn should_enforce_assist(&self) -> bool {
self.enforce_assist
}

fn summary_phrase(&self, files: usize, duration: &Duration) -> MarkupBuf {
SummaryVerbExecution.summary_verb("Checked", files, duration)
}
}

impl LoadEditorConfig for CheckCommandPayload {
fn should_load_editor_config(&self, fs_configuration: &Configuration) -> bool {
self.configuration
Expand All @@ -43,8 +143,39 @@ impl LoadEditorConfig for CheckCommandPayload {
}
}

impl CommandRunner for CheckCommandPayload {
const COMMAND_NAME: &'static str = "check";
impl TraversalCommand for CheckCommandPayload {
type ProcessFile = CheckProcessFile;

fn command_name(&self) -> &'static str {
"check"
}

fn minimal_scan_kind(&self) -> Option<ScanKind> {
None
}

fn get_execution(
&self,
cli_options: &CliOptions,
_console: &mut dyn Console,
_workspace: &dyn Workspace,
) -> Result<Box<dyn Execution>, CliDiagnostic> {
let fix_file_mode = determine_fix_file_mode(FixFileModeOptions {
write: self.write,
suppress: false,
suppression_reason: None,
fix: self.fix,
unsafe_: self.unsafe_,
})?;

Ok(Box::new(CheckExecution {
fix_file_mode,
stdin_file_path: self.stdin_file_path.clone(),
vcs_targeted: (self.staged, self.changed).into(),
enforce_assist: self.enforce_assist,
skip_parse_errors: cli_options.skip_parse_errors,
}))
}

fn merge_configuration(
&mut self,
Expand Down Expand Up @@ -132,36 +263,4 @@ impl CommandRunner for CheckCommandPayload {

Ok(paths)
}

fn get_stdin_file_path(&self) -> Option<&str> {
self.stdin_file_path.as_deref()
}

fn should_write(&self) -> bool {
self.write || self.fix
}

fn get_execution(
&self,
cli_options: &CliOptions,
console: &mut dyn Console,
_workspace: &dyn Workspace,
) -> Result<Execution, CliDiagnostic> {
let fix_file_mode = determine_fix_file_mode(FixFileModeOptions {
write: self.write,
suppress: false,
suppression_reason: None,
fix: self.fix,
unsafe_: self.unsafe_,
})?;

Ok(Execution::new(TraversalMode::Check {
fix_file_mode,
stdin: self.get_stdin(console)?,
vcs_targeted: (self.staged, self.changed).into(),
enforce_assist: self.enforce_assist,
skip_parse_errors: cli_options.skip_parse_errors,
})
.set_report(cli_options))
}
}
Loading