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

lintcheck: fix table layout #13825

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
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 |
|--------------------------------------------------------------|-------|---------|---------|
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't added back that fancy ---:

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right alignment is pretty nice for number columns, the markdown is rendered on the summary page e.g. here at https://github.com/rust-lang/rust-clippy/actions/runs/12297760099?pr=13820

I believe the print in the run itself is more for debugging, personally I don't think it's worth adding a dependency for

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, added dep, yes, but lintcheck didn't distributed to users and even cached in CI.

| [`clippy::float_arithmetic`](#user-content-float-arithmetic) | 0 | 0 | 0 |";
assert_eq!(expected, get_summary_table(&lint_warnings));
}
}
Loading