mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 18:58:04 +00:00
Respect file-level # ruff: noqa
suppressions for unused-noqa
rule (#6405)
## Summary We weren't respecting `# ruff: noqa: RUF100`, i.e., file-level suppressions for the `unused-noqa` rule itself. Closes https://github.com/astral-sh/ruff/issues/6385.
This commit is contained in:
parent
3d06fe743d
commit
927cfc9564
4 changed files with 28 additions and 2 deletions
5
crates/ruff/resources/test/fixtures/ruff/RUF100_4.py
vendored
Normal file
5
crates/ruff/resources/test/fixtures/ruff/RUF100_4.py
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
# ruff: noqa: RUF100
|
||||
|
||||
import os # noqa: F401
|
||||
|
||||
print(os.sep)
|
|
@ -94,8 +94,15 @@ pub(crate) fn check_noqa(
|
|||
}
|
||||
}
|
||||
|
||||
// Enforce that the noqa directive was actually used (RUF100).
|
||||
if analyze_directives && settings.rules.enabled(Rule::UnusedNOQA) {
|
||||
// Enforce that the noqa directive was actually used (RUF100), unless RUF100 was itself
|
||||
// suppressed.
|
||||
if settings.rules.enabled(Rule::UnusedNOQA)
|
||||
&& analyze_directives
|
||||
&& !exemption.is_some_and(|exemption| match exemption {
|
||||
FileExemption::All => true,
|
||||
FileExemption::Codes(codes) => codes.contains(&Rule::UnusedNOQA.noqa_code()),
|
||||
})
|
||||
{
|
||||
for line in noqa_directives.lines() {
|
||||
match &line.directive {
|
||||
Directive::All(directive) => {
|
||||
|
|
|
@ -156,6 +156,16 @@ mod tests {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ruf100_4() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("ruff/RUF100_4.py"),
|
||||
&settings::Settings::for_rules(vec![Rule::UnusedNOQA, Rule::UnusedImport]),
|
||||
)?;
|
||||
assert_messages!(diagnostics);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn flake8_noqa() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
source: crates/ruff/src/rules/ruff/mod.rs
|
||||
---
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue