Avoid respecting noqa directives when RUF100 is enabled (#3469)

This commit is contained in:
Charlie Marsh 2023-03-12 14:37:35 -04:00 committed by GitHub
parent 6c576872d4
commit a65c6806a6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 5 deletions

View file

@ -22,7 +22,7 @@ pub fn check_noqa(
noqa_line_for: &IntMap<usize, usize>, noqa_line_for: &IntMap<usize, usize>,
settings: &Settings, settings: &Settings,
autofix: flags::Autofix, autofix: flags::Autofix,
) { ) -> Vec<usize> {
let enforce_noqa = settings.rules.enabled(&Rule::UnusedNOQA); let enforce_noqa = settings.rules.enabled(&Rule::UnusedNOQA);
// Whether the file is exempted from all checks. // Whether the file is exempted from all checks.
@ -264,7 +264,5 @@ pub fn check_noqa(
} }
ignored_diagnostics.sort_unstable(); ignored_diagnostics.sort_unstable();
for index in ignored_diagnostics.iter().rev() { ignored_diagnostics
diagnostics.swap_remove(*index);
}
} }

View file

@ -215,7 +215,7 @@ pub fn check_path(
.iter_enabled() .iter_enabled()
.any(|rule_code| rule_code.lint_source().is_noqa()) .any(|rule_code| rule_code.lint_source().is_noqa())
{ {
check_noqa( let ignored = check_noqa(
&mut diagnostics, &mut diagnostics,
contents, contents,
indexer.commented_lines(), indexer.commented_lines(),
@ -223,6 +223,11 @@ pub fn check_path(
settings, settings,
error.as_ref().map_or(autofix, |_| flags::Autofix::Disabled), error.as_ref().map_or(autofix, |_| flags::Autofix::Disabled),
); );
if noqa.into() {
for index in ignored.iter().rev() {
diagnostics.swap_remove(*index);
}
}
} }
LinterResult::new(diagnostics, error) LinterResult::new(diagnostics, error)