handle non-ruff files, update snapshots

This commit is contained in:
Brent Westbrook 2025-08-27 12:01:46 -04:00
parent 8f909ea0bb
commit 6a652d2ff3
3 changed files with 52 additions and 45 deletions

View file

@ -60,24 +60,30 @@ impl Serialize for SerializedMessages<'_> {
let mut fingerprints = HashSet::<u64>::with_capacity(self.diagnostics.len());
for diagnostic in self.diagnostics {
let span = diagnostic.expect_primary_span();
if let Some(span) = diagnostic.primary_span() {
let file = span.file();
let filename = diagnostic.expect_ruff_filename();
let filename = file.path(self.resolver);
let (start_location, end_location) = if self.resolver.is_notebook(file) {
// We can't give a reasonable location for the structured formats,
// so we show one that's clearly a fallback
Default::default()
} else {
let diagnostic_source = file.diagnostic_source(self.resolver);
let source_code = diagnostic_source.as_source_code();
span.range()
.map(|range| {
(
diagnostic.expect_ruff_start_location(),
diagnostic.expect_ruff_end_location(),
source_code.line_column(range.start()),
source_code.line_column(range.end()),
)
})
.unwrap_or_default()
};
let path = self.project_dir.as_ref().map_or_else(
|| file.relative_path(self.resolver).display().to_string(),
|project_dir| relativize_path_to(&filename, project_dir),
|project_dir| relativize_path_to(filename, project_dir),
);
let mut message_fingerprint = fingerprint(diagnostic, &path, 0);
@ -110,6 +116,7 @@ impl Serialize for SerializedMessages<'_> {
s.serialize_element(&value)?;
}
}
s.end()
}

View file

@ -1,6 +1,6 @@
---
source: crates/ruff_linter/src/message/gitlab.rs
expression: redact_fingerprint(&content)
source: crates/ruff_db/src/diagnostic/render/gitlab.rs
expression: env.render_diagnostics(&diagnostics)
---
[
{

View file

@ -1,6 +1,6 @@
---
source: crates/ruff_linter/src/message/gitlab.rs
expression: redact_fingerprint(&content)
source: crates/ruff_db/src/diagnostic/render/gitlab.rs
expression: env.render_diagnostics(&diagnostics)
---
[
{