Skip to content

Commit 13d7cf9

Browse files
committed
move empty index filtering into affected test
1 parent 67bc7b7 commit 13d7cf9

File tree

2 files changed

+18
-24
lines changed

2 files changed

+18
-24
lines changed

crates/ruff/src/cache.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ mod tests {
547547
continue;
548548
}
549549

550-
let diagnostics = lint_path(
550+
let mut diagnostics = lint_path(
551551
&path,
552552
Some(PackageRoot::root(&package_root)),
553553
&settings.linter,
@@ -557,7 +557,14 @@ mod tests {
557557
UnsafeFixes::Enabled,
558558
)
559559
.unwrap();
560-
if !diagnostics.inner.is_empty() {
560+
if diagnostics.inner.is_empty() {
561+
// We won't load a notebook index from the cache for files without diagnostics,
562+
// so remove them from `expected_diagnostics` too. This allows us to keep the
563+
// full equality assertion below.
564+
diagnostics
565+
.notebook_indexes
566+
.remove(&path.to_string_lossy().to_string());
567+
} else {
561568
paths_with_diagnostics.push(path.clone());
562569
}
563570
paths.push(path);

crates/ruff/src/diagnostics.rs

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -329,17 +329,10 @@ pub(crate) fn lint_path(
329329
cache.set_linted(relative_path.to_owned(), &key, linted);
330330
}
331331

332-
// Avoid constructing a map when there are no diagnostics. The index is only used for rendering
333-
// diagnostics anyway. This mirrors our caching behavior, which does not preserve an empty index
334-
// either.
335-
let notebook_indexes = if diagnostics.is_empty() {
336-
FxHashMap::default()
332+
let notebook_indexes = if let SourceKind::IpyNotebook(notebook) = transformed {
333+
FxHashMap::from_iter([(path.to_string_lossy().to_string(), notebook.into_index())])
337334
} else {
338-
if let SourceKind::IpyNotebook(notebook) = transformed {
339-
FxHashMap::from_iter([(path.to_string_lossy().to_string(), notebook.into_index())])
340-
} else {
341-
FxHashMap::default()
342-
}
335+
FxHashMap::default()
343336
};
344337

345338
Ok(Diagnostics {
@@ -477,19 +470,13 @@ pub(crate) fn lint_stdin(
477470
(result, transformed, fixed)
478471
};
479472

480-
// Avoid constructing a map when there are no diagnostics. The index is only used for rendering
481-
// diagnostics anyway.
482-
let notebook_indexes = if diagnostics.is_empty() {
483-
FxHashMap::default()
473+
let notebook_indexes = if let SourceKind::IpyNotebook(notebook) = transformed {
474+
FxHashMap::from_iter([(
475+
path.map_or_else(|| "-".into(), |path| path.to_string_lossy().to_string()),
476+
notebook.into_index(),
477+
)])
484478
} else {
485-
if let SourceKind::IpyNotebook(notebook) = transformed {
486-
FxHashMap::from_iter([(
487-
path.map_or_else(|| "-".into(), |path| path.to_string_lossy().to_string()),
488-
notebook.into_index(),
489-
)])
490-
} else {
491-
FxHashMap::default()
492-
}
479+
FxHashMap::default()
493480
};
494481

495482
Ok(Diagnostics {

0 commit comments

Comments
 (0)