Respect per-file-ignores for RUF100 with no other diagnostics (#11058)

## Summary

The existing test didn't cover the case in which there are _no_ other
diagnostics in the file.

Closes https://github.com/astral-sh/ruff/issues/10906.
This commit is contained in:
Charlie Marsh 2024-04-20 11:33:22 -04:00 committed by GitHub
parent c80b9a4a90
commit d544199272
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 29 additions and 1 deletions

View file

@ -265,7 +265,13 @@ pub fn check_path(
}
// Ignore diagnostics based on per-file-ignores.
let per_file_ignores = if !diagnostics.is_empty() && !settings.per_file_ignores.is_empty() {
let per_file_ignores = if (!diagnostics.is_empty()
|| settings
.rules
.iter_enabled()
.any(|rule_code| rule_code.lint_source().is_noqa()))
&& !settings.per_file_ignores.is_empty()
{
fs::ignores_from_path(path, &settings.per_file_ignores)
} else {
RuleSet::empty()