mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-29 18:23:49 +00:00
Auto merge of #13133 - xFrednet:lintcheck-linkify-summary, r=Alexendoo
Lintcheck: Cleanup of Lintcheck's CI summery This PR makes three changes to lintcheck's job summary: * Adds links to the *Added*, *Removed*, *Changed* sections * Added the crate name to the warning info * Removes empty lines from the rendered output This is what the new output roughly looks like: ![image](https://github.com/user-attachments/assets/3faae0a6-e5ee-4e70-9d4d-d19b18dc6a3a) ![image](https://github.com/user-attachments/assets/028c3a92-98dc-4e00-b7bb-fecf9450f5b1) [🖼️ Old Output 🖼️](https://github.com/xFrednet/rust-clippy/actions/runs/10019681444) [🖼️ New Output 🖼️](https://github.com/xFrednet/rust-clippy/actions/runs/10019598141) The links for the sections are a bit weird as you have to click on them twice. I believe this is a bug from GH's side. But it works reasonably well :D --- changelog: none r? `@Alexendoo`
This commit is contained in:
commit
7f0ed11213
@ -9,6 +9,7 @@ use crate::ClippyWarning;
|
|||||||
#[derive(Deserialize, Serialize)]
|
#[derive(Deserialize, Serialize)]
|
||||||
struct LintJson {
|
struct LintJson {
|
||||||
lint: String,
|
lint: String,
|
||||||
|
krate: String,
|
||||||
file_name: String,
|
file_name: String,
|
||||||
byte_pos: (u32, u32),
|
byte_pos: (u32, u32),
|
||||||
file_link: String,
|
file_link: String,
|
||||||
@ -19,6 +20,10 @@ impl LintJson {
|
|||||||
fn key(&self) -> impl Ord + '_ {
|
fn key(&self) -> impl Ord + '_ {
|
||||||
(self.file_name.as_str(), self.byte_pos, self.lint.as_str())
|
(self.file_name.as_str(), self.byte_pos, self.lint.as_str())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn info_text(&self, action: &str) -> String {
|
||||||
|
format!("{action} `{}` in `{}` at {}", self.lint, self.krate, self.file_link)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Creates the log file output for [`crate::config::OutputFormat::Json`]
|
/// Creates the log file output for [`crate::config::OutputFormat::Json`]
|
||||||
@ -30,6 +35,7 @@ pub(crate) fn output(clippy_warnings: Vec<ClippyWarning>) -> String {
|
|||||||
LintJson {
|
LintJson {
|
||||||
file_name: span.file_name.clone(),
|
file_name: span.file_name.clone(),
|
||||||
byte_pos: (span.byte_start, span.byte_end),
|
byte_pos: (span.byte_start, span.byte_end),
|
||||||
|
krate: warning.krate,
|
||||||
file_link: warning.url,
|
file_link: warning.url,
|
||||||
lint: warning.lint,
|
lint: warning.lint,
|
||||||
rendered: warning.diag.rendered.unwrap(),
|
rendered: warning.diag.rendered.unwrap(),
|
||||||
@ -51,12 +57,16 @@ fn print_warnings(title: &str, warnings: &[LintJson]) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("### {title}");
|
//We have to use HTML here to be able to manually add an id.
|
||||||
|
println!(r#"<h3 id="{title}">{title}</h3>"#);
|
||||||
|
println!();
|
||||||
for warning in warnings {
|
for warning in warnings {
|
||||||
println!("{title} `{}` at {}", warning.lint, warning.file_link);
|
println!("{}", warning.info_text(title));
|
||||||
|
println!();
|
||||||
println!("```");
|
println!("```");
|
||||||
print!("{}", warning.rendered);
|
println!("{}", warning.rendered.trim_end());
|
||||||
println!("```");
|
println!("```");
|
||||||
|
println!();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -65,11 +75,14 @@ fn print_changed_diff(changed: &[(LintJson, LintJson)]) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
println!("### Changed");
|
//We have to use HTML here to be able to manually add an id.
|
||||||
|
println!(r#"<h3 id="changed">Changed</h3>"#);
|
||||||
|
println!();
|
||||||
for (old, new) in changed {
|
for (old, new) in changed {
|
||||||
println!("Changed `{}` at {}", new.lint, new.file_link);
|
println!("{}", new.info_text("Changed"));
|
||||||
|
println!();
|
||||||
println!("```diff");
|
println!("```diff");
|
||||||
for change in diff::lines(&old.rendered, &new.rendered) {
|
for change in diff::lines(old.rendered.trim_end(), new.rendered.trim_end()) {
|
||||||
use diff::Result::{Both, Left, Right};
|
use diff::Result::{Both, Left, Right};
|
||||||
|
|
||||||
match change {
|
match change {
|
||||||
@ -109,13 +122,30 @@ pub(crate) fn diff(old_path: &Path, new_path: &Path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
print!(
|
print!(
|
||||||
"{} added, {} removed, {} changed\n\n",
|
r##"{}, {}, {}"##,
|
||||||
added.len(),
|
count_string("added", added.len()),
|
||||||
removed.len(),
|
count_string("removed", removed.len()),
|
||||||
changed.len()
|
count_string("changed", changed.len()),
|
||||||
);
|
);
|
||||||
|
println!();
|
||||||
|
println!();
|
||||||
|
|
||||||
print_warnings("Added", &added);
|
print_warnings("Added", &added);
|
||||||
print_warnings("Removed", &removed);
|
print_warnings("Removed", &removed);
|
||||||
print_changed_diff(&changed);
|
print_changed_diff(&changed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// This generates the `x added` string for the start of the job summery.
|
||||||
|
/// It linkifies them if possible to jump to the respective heading.
|
||||||
|
fn count_string(label: &str, count: usize) -> String {
|
||||||
|
// Headlines are only added, if anything will be displayed under the headline.
|
||||||
|
// We therefore only want to add links to them if they exist
|
||||||
|
if count == 0 {
|
||||||
|
format!("0 {label}")
|
||||||
|
} else {
|
||||||
|
// GitHub's job summaries don't add HTML ids to headings. That's why we
|
||||||
|
// manually have to add them. GitHub prefixes these manual ids with
|
||||||
|
// `user-content-` and that's how we end up with these awesome links :D
|
||||||
|
format!("[{count} {label}](#user-content-{label})")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -189,6 +189,7 @@ impl Crate {
|
|||||||
Ok(Message::CompilerMessage(message)) => ClippyWarning::new(
|
Ok(Message::CompilerMessage(message)) => ClippyWarning::new(
|
||||||
normalize_diag(message.message, shared_target_dir.to_str().unwrap()),
|
normalize_diag(message.message, shared_target_dir.to_str().unwrap()),
|
||||||
&self.base_url,
|
&self.base_url,
|
||||||
|
&self.name,
|
||||||
),
|
),
|
||||||
_ => None,
|
_ => None,
|
||||||
})
|
})
|
||||||
|
@ -53,12 +53,13 @@ impl RustcIce {
|
|||||||
pub struct ClippyWarning {
|
pub struct ClippyWarning {
|
||||||
pub lint: String,
|
pub lint: String,
|
||||||
pub diag: Diagnostic,
|
pub diag: Diagnostic,
|
||||||
|
pub krate: String,
|
||||||
/// The URL that points to the file and line of the lint emission
|
/// The URL that points to the file and line of the lint emission
|
||||||
pub url: String,
|
pub url: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ClippyWarning {
|
impl ClippyWarning {
|
||||||
pub fn new(mut diag: Diagnostic, base_url: &str) -> Option<Self> {
|
pub fn new(mut diag: Diagnostic, base_url: &str, krate: &str) -> Option<Self> {
|
||||||
let lint = diag.code.clone()?.code;
|
let lint = diag.code.clone()?.code;
|
||||||
if !(lint.contains("clippy") || diag.message.contains("clippy"))
|
if !(lint.contains("clippy") || diag.message.contains("clippy"))
|
||||||
|| diag.message.contains("could not read cargo metadata")
|
|| diag.message.contains("could not read cargo metadata")
|
||||||
@ -90,7 +91,12 @@ impl ClippyWarning {
|
|||||||
file.clone()
|
file.clone()
|
||||||
};
|
};
|
||||||
|
|
||||||
Some(Self { lint, diag, url })
|
Some(Self {
|
||||||
|
lint,
|
||||||
|
diag,
|
||||||
|
url,
|
||||||
|
krate: krate.to_string(),
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn span(&self) -> &DiagnosticSpan {
|
pub fn span(&self) -> &DiagnosticSpan {
|
||||||
|
@ -72,7 +72,7 @@ fn process_stream(
|
|||||||
let messages = stderr
|
let messages = stderr
|
||||||
.lines()
|
.lines()
|
||||||
.filter_map(|json_msg| serde_json::from_str::<Diagnostic>(json_msg).ok())
|
.filter_map(|json_msg| serde_json::from_str::<Diagnostic>(json_msg).ok())
|
||||||
.filter_map(|diag| ClippyWarning::new(diag, &base_url));
|
.filter_map(|diag| ClippyWarning::new(diag, &base_url, &driver_info.package_name));
|
||||||
|
|
||||||
for message in messages {
|
for message in messages {
|
||||||
sender.send(message).unwrap();
|
sender.send(message).unwrap();
|
||||||
|
Loading…
Reference in New Issue
Block a user