Skip to content

Commit

Permalink
Use a hash to fingerprint GitLab CI output (#3456)
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Mar 12, 2023
1 parent 0f78f27 commit 7fb7268
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion crates/ruff_cli/src/printer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use std::cmp::Reverse;
use std::collections::hash_map::DefaultHasher;
use std::collections::BTreeMap;
use std::fmt::Display;
use std::hash::{Hash, Hasher};
use std::io;
use std::io::{BufWriter, Write};
use std::path::Path;
Expand Down Expand Up @@ -350,7 +352,7 @@ impl Printer {
json!({
"description": format!("({}) {}", message.kind.rule().noqa_code(), message.kind.body),
"severity": "major",
"fingerprint": message.kind.rule().noqa_code().to_string(),
"fingerprint": fingerprint(message),
"location": {
"path": message.filename,
"lines": {
Expand Down Expand Up @@ -553,6 +555,18 @@ fn num_digits(n: usize) -> usize {
.max(1)
}

/// Generate a unique fingerprint to identify a violation.
fn fingerprint(message: &Message) -> String {
let mut hasher = DefaultHasher::new();
message.kind.rule().hash(&mut hasher);
message.location.row().hash(&mut hasher);
message.location.column().hash(&mut hasher);
message.end_location.row().hash(&mut hasher);
message.end_location.column().hash(&mut hasher);
message.filename.hash(&mut hasher);
format!("{:x}", hasher.finish())
}

struct CodeAndBody<'a>(&'a Message, fix::FixMode);

impl Display for CodeAndBody<'_> {
Expand Down

0 comments on commit 7fb7268

Please sign in to comment.