From 14c5ed5d7dc8c51e3436e06e5e4d15bb7f7aa9c5 Mon Sep 17 00:00:00 2001 From: Micha Reiser Date: Fri, 14 Mar 2025 09:37:16 +0100 Subject: [PATCH] =?UTF-8?q?[`pygrep-hooks`]:=20Detect=20file-level=20suppr?= =?UTF-8?q?essions=20comments=20without=20rul=E2=80=A6=20(#16720)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Summary I accidentially dropped this commit from the Ruff 0.10 release. See https://github.com/astral-sh/ruff/pull/16699 --- crates/ruff_linter/src/checkers/noqa.rs | 1 - .../ruff_linter/src/rules/pygrep_hooks/mod.rs | 19 ------------- .../rules/pygrep_hooks/rules/blanket_noqa.rs | 27 +++++++------------ ...grep_hooks__tests__PGH004_PGH004_2.py.snap | 16 ++++++++++- ...s__tests__preview__PGH004_PGH004_2.py.snap | 26 ------------------ 5 files changed, 24 insertions(+), 65 deletions(-) delete mode 100644 crates/ruff_linter/src/rules/pygrep_hooks/snapshots/ruff_linter__rules__pygrep_hooks__tests__preview__PGH004_PGH004_2.py.snap diff --git a/crates/ruff_linter/src/checkers/noqa.rs b/crates/ruff_linter/src/checkers/noqa.rs index 4d3015eadd..be47bac452 100644 --- a/crates/ruff_linter/src/checkers/noqa.rs +++ b/crates/ruff_linter/src/checkers/noqa.rs @@ -224,7 +224,6 @@ pub(crate) fn check_noqa( &noqa_directives, locator, &file_noqa_directives, - settings.preview, ); } diff --git a/crates/ruff_linter/src/rules/pygrep_hooks/mod.rs b/crates/ruff_linter/src/rules/pygrep_hooks/mod.rs index 52df6929af..adc4e91fa6 100644 --- a/crates/ruff_linter/src/rules/pygrep_hooks/mod.rs +++ b/crates/ruff_linter/src/rules/pygrep_hooks/mod.rs @@ -10,7 +10,6 @@ mod tests { use crate::registry::Rule; - use crate::settings::types::PreviewMode; use crate::test::test_path; use crate::{assert_messages, settings}; @@ -30,22 +29,4 @@ mod tests { assert_messages!(snapshot, diagnostics); Ok(()) } - - #[test_case(Rule::BlanketNOQA, Path::new("PGH004_2.py"))] - fn preview_rules(rule_code: Rule, path: &Path) -> Result<()> { - let snapshot = format!( - "preview__{}_{}", - rule_code.noqa_code(), - path.to_string_lossy() - ); - let diagnostics = test_path( - Path::new("pygrep_hooks").join(path).as_path(), - &settings::LinterSettings { - preview: PreviewMode::Enabled, - ..settings::LinterSettings::for_rule(rule_code) - }, - )?; - assert_messages!(snapshot, diagnostics); - Ok(()) - } } diff --git a/crates/ruff_linter/src/rules/pygrep_hooks/rules/blanket_noqa.rs b/crates/ruff_linter/src/rules/pygrep_hooks/rules/blanket_noqa.rs index 5f48e00abd..b0fe9532d8 100644 --- a/crates/ruff_linter/src/rules/pygrep_hooks/rules/blanket_noqa.rs +++ b/crates/ruff_linter/src/rules/pygrep_hooks/rules/blanket_noqa.rs @@ -4,7 +4,6 @@ use ruff_python_trivia::Cursor; use ruff_text_size::{Ranged, TextRange}; use crate::noqa::{self, Directive, FileNoqaDirectives, NoqaDirectives}; -use crate::settings::types::PreviewMode; use crate::Locator; /// ## What it does @@ -18,9 +17,6 @@ use crate::Locator; /// maintain, as the annotation does not clarify which diagnostics are intended /// to be suppressed. /// -/// In [preview], this rule also checks for blanket file-level annotations (e.g., -/// `# ruff: noqa`, as opposed to `# ruff: noqa: F401`). -/// /// ## Example /// ```python /// from .base import * # noqa @@ -41,8 +37,6 @@ use crate::Locator; /// /// ## References /// - [Ruff documentation](https://docs.astral.sh/ruff/configuration/#error-suppression) -/// -/// [preview]: https://docs.astral.sh/ruff/preview/ #[derive(ViolationMetadata)] pub(crate) struct BlanketNOQA { missing_colon: bool, @@ -84,19 +78,16 @@ pub(crate) fn blanket_noqa( noqa_directives: &NoqaDirectives, locator: &Locator, file_noqa_directives: &FileNoqaDirectives, - preview: PreviewMode, ) { - if preview.is_enabled() { - for line in file_noqa_directives.lines() { - if let Directive::All(_) = line.parsed_file_exemption { - diagnostics.push(Diagnostic::new( - BlanketNOQA { - missing_colon: false, - file_exemption: true, - }, - line.range(), - )); - } + for line in file_noqa_directives.lines() { + if let Directive::All(_) = line.parsed_file_exemption { + diagnostics.push(Diagnostic::new( + BlanketNOQA { + missing_colon: false, + file_exemption: true, + }, + line.range(), + )); } } diff --git a/crates/ruff_linter/src/rules/pygrep_hooks/snapshots/ruff_linter__rules__pygrep_hooks__tests__PGH004_PGH004_2.py.snap b/crates/ruff_linter/src/rules/pygrep_hooks/snapshots/ruff_linter__rules__pygrep_hooks__tests__PGH004_PGH004_2.py.snap index 609af05ed0..6c93b8a108 100644 --- a/crates/ruff_linter/src/rules/pygrep_hooks/snapshots/ruff_linter__rules__pygrep_hooks__tests__PGH004_PGH004_2.py.snap +++ b/crates/ruff_linter/src/rules/pygrep_hooks/snapshots/ruff_linter__rules__pygrep_hooks__tests__PGH004_PGH004_2.py.snap @@ -1,6 +1,5 @@ --- source: crates/ruff_linter/src/rules/pygrep_hooks/mod.rs -snapshot_kind: text --- PGH004_2.py:1:1: PGH004 Use specific rule codes when using `noqa` | @@ -9,3 +8,18 @@ PGH004_2.py:1:1: PGH004 Use specific rule codes when using `noqa` 2 | # ruff : noqa 3 | # ruff: noqa: F401 | + +PGH004_2.py:2:1: PGH004 Use specific rule codes when using `ruff: noqa` + | +1 | # noqa +2 | # ruff : noqa + | ^^^^^^^^^^^^^ PGH004 +3 | # ruff: noqa: F401 + | + +PGH004_2.py:6:1: PGH004 Use specific rule codes when using `ruff: noqa` + | +6 | # flake8: noqa + | ^^^^^^^^^^^^^^ PGH004 +7 | import math as m + | diff --git a/crates/ruff_linter/src/rules/pygrep_hooks/snapshots/ruff_linter__rules__pygrep_hooks__tests__preview__PGH004_PGH004_2.py.snap b/crates/ruff_linter/src/rules/pygrep_hooks/snapshots/ruff_linter__rules__pygrep_hooks__tests__preview__PGH004_PGH004_2.py.snap deleted file mode 100644 index ca34924cd7..0000000000 --- a/crates/ruff_linter/src/rules/pygrep_hooks/snapshots/ruff_linter__rules__pygrep_hooks__tests__preview__PGH004_PGH004_2.py.snap +++ /dev/null @@ -1,26 +0,0 @@ ---- -source: crates/ruff_linter/src/rules/pygrep_hooks/mod.rs -snapshot_kind: text ---- -PGH004_2.py:1:1: PGH004 Use specific rule codes when using `noqa` - | -1 | # noqa - | ^^^^^^ PGH004 -2 | # ruff : noqa -3 | # ruff: noqa: F401 - | - -PGH004_2.py:2:1: PGH004 Use specific rule codes when using `ruff: noqa` - | -1 | # noqa -2 | # ruff : noqa - | ^^^^^^^^^^^^^ PGH004 -3 | # ruff: noqa: F401 - | - -PGH004_2.py:6:1: PGH004 Use specific rule codes when using `ruff: noqa` - | -6 | # flake8: noqa - | ^^^^^^^^^^^^^^ PGH004 -7 | import math as m - |