mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-30 22:01:47 +00:00
Respect unused-noqa
via per-file-ignores
(#9300)
## Summary If `RUF100` is ignored via `per-file-ignores`, we need to avoid raising it. `RUF100` has special "self-ignore" logic, since the rule itself deals with `# noqa` directives. This PR wires up `per-file-ignores` to that "self-ignore" logic. Closes https://github.com/astral-sh/ruff/issues/9297.
This commit is contained in:
parent
5d4825b60f
commit
e178d938cc
5 changed files with 38 additions and 8 deletions
|
@ -31,7 +31,7 @@ use crate::fix::{fix_file, FixResult};
|
|||
use crate::logging::DisplayParseError;
|
||||
use crate::message::Message;
|
||||
use crate::noqa::add_noqa;
|
||||
use crate::registry::{AsRule, Rule};
|
||||
use crate::registry::{AsRule, Rule, RuleSet};
|
||||
use crate::rules::pycodestyle;
|
||||
use crate::settings::types::UnsafeFixes;
|
||||
use crate::settings::{flags, LinterSettings};
|
||||
|
@ -213,12 +213,14 @@ pub fn check_path(
|
|||
}
|
||||
|
||||
// Ignore diagnostics based on per-file-ignores.
|
||||
if !diagnostics.is_empty() && !settings.per_file_ignores.is_empty() {
|
||||
let ignores = fs::ignores_from_path(path, &settings.per_file_ignores);
|
||||
if !ignores.is_empty() {
|
||||
diagnostics.retain(|diagnostic| !ignores.contains(diagnostic.kind.rule()));
|
||||
}
|
||||
let per_file_ignores = if !diagnostics.is_empty() && !settings.per_file_ignores.is_empty() {
|
||||
fs::ignores_from_path(path, &settings.per_file_ignores)
|
||||
} else {
|
||||
RuleSet::empty()
|
||||
};
|
||||
if !per_file_ignores.is_empty() {
|
||||
diagnostics.retain(|diagnostic| !per_file_ignores.contains(diagnostic.kind.rule()));
|
||||
}
|
||||
|
||||
// Enforce `noqa` directives.
|
||||
if (noqa.into() && !diagnostics.is_empty())
|
||||
|
@ -234,6 +236,7 @@ pub fn check_path(
|
|||
indexer.comment_ranges(),
|
||||
&directives.noqa_line_for,
|
||||
error.is_none(),
|
||||
&per_file_ignores,
|
||||
settings,
|
||||
);
|
||||
if noqa.into() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue