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/chubby-dancers-design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@biomejs/biome": patch
---

The `summary` reporter doesn't take `--max-diagnostics` into account anymore.
5 changes: 5 additions & 0 deletions .changeset/twelve-streets-drop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@biomejs/biome": patch
---

The `summary` reporter now prints the files processed and the files fixed when passing the `--verbose` flag.
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 @@ -120,7 +120,7 @@ impl FromStr for ColorsArg {
}
}

#[derive(Debug, Default, Clone)]
#[derive(Debug, Default, Clone, Eq, PartialEq)]
pub enum CliReporter {
/// The default reporter
#[default]
Expand Down
2 changes: 2 additions & 0 deletions crates/biome_cli/src/execute/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,8 @@ pub fn execute_mode(
diagnostics_payload,
execution: execution.clone(),
verbose: cli_options.verbose,
working_directory: fs.working_directory().clone(),
evaluated_paths,
};
reporter.write(&mut SummaryReporterVisitor(console))?;
} else {
Expand Down
25 changes: 24 additions & 1 deletion crates/biome_cli/src/reporter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ pub(crate) mod terminal;

use crate::cli_options::MaxDiagnostics;
use crate::execute::Execution;
use biome_diagnostics::{Error, Severity};
use biome_diagnostics::advice::ListAdvice;
use biome_diagnostics::{Diagnostic, Error, Severity};
use biome_fs::BiomePath;
use camino::Utf8PathBuf;
use serde::Serialize;
Expand Down Expand Up @@ -74,3 +75,25 @@ pub trait ReporterVisitor {
_verbose: bool,
) -> io::Result<()>;
}

#[derive(Debug, Diagnostic)]
#[diagnostic(
tags(VERBOSE),
severity = Information,
message = "Files fixed:"
)]
pub(crate) struct FixedPathsDiagnostic {
#[advice]
advice: ListAdvice<String>,
}

#[derive(Debug, Diagnostic)]
#[diagnostic(
tags(VERBOSE),
severity = Information,
message = "Files processed:"
)]
pub(crate) struct EvaluatedPathsDiagnostic {
#[advice]
advice: ListAdvice<String>,
}
60 changes: 54 additions & 6 deletions crates/biome_cli/src/reporter/summary.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
use crate::reporter::terminal::ConsoleTraversalSummary;
use crate::reporter::{EvaluatedPathsDiagnostic, FixedPathsDiagnostic};
use crate::{DiagnosticsPayload, Execution, Reporter, ReporterVisitor, TraversalSummary};
use biome_console::fmt::{Display, Formatter};
use biome_console::{Console, ConsoleExt, markup};
use biome_diagnostics::advice::ListAdvice;
use biome_diagnostics::{
Advices, Category, Diagnostic, MessageAndDescription, PrintDiagnostic, Resource, Severity,
Visit, category,
};
use biome_fs::BiomePath;
use camino::Utf8PathBuf;
use std::cmp::Ordering;
use std::collections::{BTreeMap, BTreeSet};
use std::fmt::Debug;
Expand All @@ -15,12 +19,17 @@ pub(crate) struct SummaryReporter {
pub(crate) summary: TraversalSummary,
pub(crate) diagnostics_payload: DiagnosticsPayload,
pub(crate) execution: Execution,
pub(crate) evaluated_paths: BTreeSet<BiomePath>,
pub(crate) working_directory: Option<Utf8PathBuf>,
pub(crate) verbose: bool,
}

impl Reporter for SummaryReporter {
fn write(self, visitor: &mut dyn ReporterVisitor) -> io::Result<()> {
visitor.report_diagnostics(&self.execution, self.diagnostics_payload, self.verbose)?;
if self.verbose {
visitor.report_handled_paths(self.evaluated_paths, self.working_directory)?;
}
visitor.report_summary(&self.execution, self.summary, self.verbose)?;
Ok(())
}
Expand Down Expand Up @@ -64,12 +73,8 @@ impl ReporterVisitor for SummaryReporterVisitor<'_> {
) -> io::Result<()> {
let mut files_to_diagnostics = FileToDiagnostics::default();

let iter = diagnostics_payload.diagnostics.iter().rev().enumerate();
for (index, diagnostic) in iter {
if diagnostics_payload.max_diagnostics.exceeded(index + 1) {
break;
}

let iter = diagnostics_payload.diagnostics.iter().rev();
for diagnostic in iter {
let location = diagnostic.location().resource.and_then(|r| match r {
Resource::File(p) => Some(p),
_ => None,
Expand Down Expand Up @@ -127,6 +132,49 @@ impl ReporterVisitor for SummaryReporterVisitor<'_> {

Ok(())
}

fn report_handled_paths(
&mut self,
evaluated_paths: BTreeSet<BiomePath>,
working_directory: Option<Utf8PathBuf>,
) -> io::Result<()> {
let evaluated_paths_diagnostic = EvaluatedPathsDiagnostic {
advice: ListAdvice {
list: evaluated_paths
.iter()
.map(|p| {
working_directory
.as_ref()
.and_then(|wd| {
p.strip_prefix(wd.as_str())
.map(|path| path.to_string())
.ok()
})
.unwrap_or(p.to_string())
})
.collect(),
},
};

let fixed_paths_diagnostic = FixedPathsDiagnostic {
advice: ListAdvice {
list: evaluated_paths
.iter()
.filter(|p| p.was_written())
.map(|p| p.to_string())
.collect(),
},
};

self.0.log(markup! {
{PrintDiagnostic::verbose(&evaluated_paths_diagnostic)}
});
self.0.log(markup! {
{PrintDiagnostic::verbose(&fixed_paths_diagnostic)}
});

Ok(())
}
}

#[derive(Debug, Default)]
Expand Down
29 changes: 5 additions & 24 deletions crates/biome_cli/src/reporter/terminal.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
use crate::Reporter;
use crate::execute::{Execution, TraversalMode};
use crate::reporter::{DiagnosticsPayload, ReporterVisitor, TraversalSummary};
use crate::reporter::{
DiagnosticsPayload, EvaluatedPathsDiagnostic, FixedPathsDiagnostic, ReporterVisitor,
TraversalSummary,
};
use biome_console::fmt::Formatter;
use biome_console::{Console, ConsoleExt, fmt, markup};
use biome_diagnostics::PrintDiagnostic;
use biome_diagnostics::advice::ListAdvice;
use biome_diagnostics::{Diagnostic, PrintDiagnostic};
use biome_fs::BiomePath;
use camino::Utf8PathBuf;
use std::collections::BTreeSet;
Expand All @@ -31,28 +34,6 @@ impl Reporter for ConsoleReporter {
}
}

#[derive(Debug, Diagnostic)]
#[diagnostic(
tags(VERBOSE),
severity = Information,
message = "Files processed:"
)]
struct EvaluatedPathsDiagnostic {
#[advice]
advice: ListAdvice<String>,
}

#[derive(Debug, Diagnostic)]
#[diagnostic(
tags(VERBOSE),
severity = Information,
message = "Files fixed:"
)]
struct FixedPathsDiagnostic {
#[advice]
advice: ListAdvice<String>,
}

pub(crate) struct ConsoleReporterVisitor<'a>(pub(crate) &'a mut dyn Console);

impl ReporterVisitor for ConsoleReporterVisitor<'_> {
Expand Down
45 changes: 41 additions & 4 deletions crates/biome_cli/tests/cases/reporter_summary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ fn reports_diagnostics_summary_check_command() {
[
"check",
"--reporter=summary",
"--max-diagnostics=200",
file_path1.as_str(),
file_path2.as_str(),
file_path3.as_str(),
Expand Down Expand Up @@ -117,7 +116,6 @@ fn reports_diagnostics_summary_ci_command() {
[
"ci",
"--reporter=summary",
"--max-diagnostics=200",
file_path1.as_str(),
file_path2.as_str(),
file_path3.as_str(),
Expand Down Expand Up @@ -158,7 +156,6 @@ fn reports_diagnostics_summary_lint_command() {
[
"lint",
"--reporter=summary",
"--max-diagnostics=200",
file_path1.as_str(),
file_path2.as_str(),
file_path3.as_str(),
Expand Down Expand Up @@ -199,7 +196,6 @@ fn reports_diagnostics_summary_format_command() {
[
"format",
"--reporter=summary",
"--max-diagnostics=200",
file_path1.as_str(),
file_path2.as_str(),
file_path3.as_str(),
Expand All @@ -218,3 +214,44 @@ fn reports_diagnostics_summary_format_command() {
result,
));
}

#[test]
fn reports_diagnostics_summary_check_verbose_command() {
let mut fs = MemoryFileSystem::default();
let mut console = BufferConsole::default();

let file_path1 = Utf8Path::new("main.ts");
fs.insert(file_path1.into(), MAIN_1.as_bytes());

let file_path2 = Utf8Path::new("index.ts");
fs.insert(file_path2.into(), MAIN_2.as_bytes());

let file_path3 = Utf8Path::new("index.css");
fs.insert(file_path3.into(), MAIN_3.as_bytes());

let (fs, result) = run_cli(
fs,
&mut console,
Args::from(
[
"check",
"--reporter=summary",
"--verbose",
file_path1.as_str(),
file_path2.as_str(),
file_path3.as_str(),
]
.as_slice(),
),
);

assert!(result.is_err(), "run_cli returned {result:?}");

assert_cli_snapshot(SnapshotPayload::new(
module_path!(),
"reports_diagnostics_summary_check_verbose_command",
fs,
console,
result,
));
}
Loading