Skip to content

Commit

Permalink
lintcheck: print accurate table of diff lints
Browse files Browse the repository at this point in the history
  • Loading branch information
klensy committed Dec 14, 2024
1 parent 3fdc8c3 commit 90baf7e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 25 deletions.
1 change: 1 addition & 0 deletions lintcheck/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0.85"
strip-ansi-escapes = "0.2.0"
tar = "0.4"
tabled = { version = "0.15", default-features = false, features = ["std"] }
toml = "0.7.3"
ureq = { version = "2.2", features = ["json"] }
walkdir = "2.3"
41 changes: 16 additions & 25 deletions lintcheck/src/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ use std::path::Path;

use itertools::{EitherOrBoth, Itertools};
use serde::{Deserialize, Serialize};
use tabled::builder::Builder;
use tabled::settings::Style;

use crate::ClippyWarning;

Expand Down Expand Up @@ -146,32 +148,21 @@ fn print_lint_warnings(lint: &LintWarnings, truncate_after: usize) {
}

fn get_summary_table(lints: &[LintWarnings]) -> String {
use std::fmt::Write;

let mut out = String::new();
let _ = writeln!(
out,
"| Lint | Added | Removed | Changed |"
);
let _ = writeln!(
out,
"| ------------------------------------------ | ------: | ------: | ------: |"
);
let mut builder = Builder::default();
builder.push_record(vec!["Lint", "Added", "Removed", "Changed"]);

for lint in lints {
let _ = writeln!(
out,
"| {:<62} | {:>7} | {:>7} | {:>7} |",
format!("[`{}`](#user-content-{})", lint.name, to_html_id(&lint.name)),
lint.added.len(),
lint.removed.len(),
lint.changed.len()
);
let lint_name = format!("[`{}`](#user-content-{})", lint.name, to_html_id(&lint.name));
builder.push_record(vec![
lint_name,
lint.added.len().to_string(),
lint.removed.len().to_string(),
lint.changed.len().to_string(),
]);
}
let mut table = builder.build();

// remove last \n
out.pop();
out
format!("{}", table.with(Style::markdown()))
}

fn print_warnings(title: &str, warnings: &[LintJson], truncate_after: usize) {
Expand Down Expand Up @@ -282,9 +273,9 @@ mod test {
changed: vec![],
}];

let expected = "| Lint | Added | Removed | Changed |
| ------------------------------------------ | ------: | ------: | ------: |
| [`clippy::float_arithmetic`](#user-content-float-arithmetic) | 0 | 0 | 0 |";
let expected = "| Lint | Added | Removed | Changed |
|--------------------------------------------------------------|-------|---------|---------|
| [`clippy::float_arithmetic`](#user-content-float-arithmetic) | 0 | 0 | 0 |";
assert_eq!(expected, get_summary_table(&lint_warnings));
}
}

0 comments on commit 90baf7e

Please sign in to comment.