Skip to content

Commit

Permalink
feat(cli): add diagnostic summary (#2742)
Browse files Browse the repository at this point in the history
  • Loading branch information
ematipico committed May 20, 2024
1 parent a810318 commit cead069
Show file tree
Hide file tree
Showing 21 changed files with 1,024 additions and 39 deletions.
25 changes: 25 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,31 @@ our [guidelines for writing a good changelog entry](https://github.com/biomejs/b
Contributed by @Conaclos
- Add a new `--reporter` called `summary`. This reporter will print diagnostics in a different way, based on the tools (formatter, linter, etc.) that are executed.
Import sorting and formatter shows the name of the files that require formatting. Instead, the linter will group the number of rules triggered and the number of errors/warnings:
```
Formatter ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
The following files needs to be formatted:
main.ts
index.ts
Organize Imports ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
The following files needs to have their imports sorted:
main.ts
index.ts
Analyzer ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Some analyzer rules were triggered
Rule Name Diagnostics
lint/suspicious/noImplicitAnyLet 12 (12 error(s), 0 warning(s), 0 info(s))
lint/suspicious/noDoubleEquals 8 (8 error(s), 0 warning(s), 0 info(s))
lint/suspicious/noRedeclare 12 (12 error(s), 0 warning(s), 0 info(s))
lint/suspicious/noDebugger 20 (20 error(s), 0 warning(s), 0 info(s))
```
Contributed by @ematipico
### Configuration
#### New features
Expand Down
6 changes: 5 additions & 1 deletion crates/biome_cli/src/cli_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub struct CliOptions {
/// Allows to change how diagnostics and summary are reported.
#[bpaf(
long("reporter"),
argument("json|json-pretty"),
argument("json|json-pretty|summary"),
fallback(CliReporter::default())
)]
pub reporter: CliReporter,
Expand Down Expand Up @@ -125,6 +125,8 @@ pub enum CliReporter {
Json,
/// Reports information using the JSON format, formatted.
JsonPretty,
/// Reports linter diagnostics grouped by category and number of hits. Reports formatter diagnostics grouped by file.
Summary,
}

impl FromStr for CliReporter {
Expand All @@ -134,6 +136,7 @@ impl FromStr for CliReporter {
match s {
"json" => Ok(Self::Json),
"json-pretty" => Ok(Self::JsonPretty),
"summary" => Ok(Self::Summary),
_ => Err(format!(
"value {s:?} is not valid for the --reporter argument"
)),
Expand All @@ -147,6 +150,7 @@ impl Display for CliReporter {
CliReporter::Default => f.write_str("default"),
CliReporter::Json => f.write_str("json"),
CliReporter::JsonPretty => f.write_str("json-pretty"),
CliReporter::Summary => f.write_str("summary"),
}
}
}
54 changes: 39 additions & 15 deletions crates/biome_cli/src/execute/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use crate::diagnostics::ReportDiagnostic;
use crate::execute::migrate::MigratePayload;
use crate::execute::traverse::traverse;
use crate::reporter::json::{JsonReporter, JsonReporterVisitor};
use crate::reporter::summary::{SummaryReporter, SummaryReporterVisitor};
use crate::reporter::terminal::{ConsoleReporter, ConsoleReporterVisitor};
use crate::{CliDiagnostic, CliSession, DiagnosticsPayload, Reporter};
use biome_configuration::linter::RuleSelector;
Expand Down Expand Up @@ -186,19 +187,29 @@ impl Display for TraversalMode {
}

/// Tells to the execution of the traversal how the information should be reported
#[derive(Copy, Clone, Default, Debug)]
#[derive(Copy, Clone, Debug)]
pub enum ReportMode {
/// Reports information straight to the console, it's the default mode
#[default]
Terminal,
Terminal { with_summary: bool },
/// Reports information in JSON format
Json { pretty: bool },
}

impl Default for ReportMode {
fn default() -> Self {
Self::Terminal {
with_summary: false,
}
}
}

impl From<CliReporter> for ReportMode {
fn from(value: CliReporter) -> Self {
match value {
CliReporter::Default => Self::Terminal,
CliReporter::Default => Self::Terminal {
with_summary: false,
},
CliReporter::Summary => Self::Terminal { with_summary: true },
CliReporter::Json => Self::Json { pretty: false },
CliReporter::JsonPretty => Self::Json { pretty: true },
}
Expand Down Expand Up @@ -388,17 +399,30 @@ pub fn execute_mode(
let should_exit_on_warnings = summary_result.warnings > 0 && cli_options.error_on_warnings;

match execution.report_mode {
ReportMode::Terminal => {
let reporter = ConsoleReporter {
summary: summary_result,
diagnostics_payload: DiagnosticsPayload {
verbose: cli_options.verbose,
diagnostic_level: cli_options.diagnostic_level,
diagnostics,
},
execution: execution.clone(),
};
reporter.write(&mut ConsoleReporterVisitor(console))?;
ReportMode::Terminal { with_summary } => {
if with_summary {
let reporter = SummaryReporter {
summary: summary_result,
diagnostics_payload: DiagnosticsPayload {
verbose: cli_options.verbose,
diagnostic_level: cli_options.diagnostic_level,
diagnostics,
},
execution: execution.clone(),
};
reporter.write(&mut SummaryReporterVisitor(console))?;
} else {
let reporter = ConsoleReporter {
summary: summary_result,
diagnostics_payload: DiagnosticsPayload {
verbose: cli_options.verbose,
diagnostic_level: cli_options.diagnostic_level,
diagnostics,
},
execution: execution.clone(),
};
reporter.write(&mut ConsoleReporterVisitor(console))?;
}
}
ReportMode::Json { pretty } => {
console.error(markup!{
Expand Down
1 change: 1 addition & 0 deletions crates/biome_cli/src/reporter/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub(crate) mod json;
pub(crate) mod summary;
pub(crate) mod terminal;

use crate::execute::Execution;
Expand Down
Loading

0 comments on commit cead069

Please sign in to comment.