Skip to content

Commit e2bc85e

Browse files
committed
pass caching tests by suppressing empty index in lint_path
1 parent 535b926 commit e2bc85e

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

crates/ruff/src/diagnostics.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -342,10 +342,17 @@ pub(crate) fn lint_path(
342342
}
343343
}
344344

345-
let notebook_indexes = if let SourceKind::IpyNotebook(notebook) = transformed {
346-
FxHashMap::from_iter([(path.to_string_lossy().to_string(), notebook.into_index())])
347-
} else {
345+
// Avoid constructing a map when there are no diagnostics. The index is only used for rendering
346+
// diagnostics anyway. This mirrors our caching behavior, which does not preserve an empty index
347+
// either.
348+
let notebook_indexes = if diagnostics.is_empty() {
348349
FxHashMap::default()
350+
} else {
351+
if let SourceKind::IpyNotebook(notebook) = transformed {
352+
FxHashMap::from_iter([(path.to_string_lossy().to_string(), notebook.into_index())])
353+
} else {
354+
FxHashMap::default()
355+
}
349356
};
350357

351358
Ok(Diagnostics {

0 commit comments

Comments
 (0)