Skip to content

apply range suppressions to filter diagnostics - #21623

Merged
amyreese merged 13 commits into
mainfrom
amy/suppress-diagnostics
Dec 9, 2025
Merged

amyreese merged 13 commits into
mainfrom
amy/suppress-diagnostics

Conversation

@amyreese

@amyreese amyreese commented Nov 25, 2025 •

Copy link
Copy Markdown
Contributor

Builds on range suppressions from #21441

Filters diagnostics based on parsed valid range suppressions.

Issue: #3711

@amyreese
amyreese changed the base branch from main to suppression-parsing November 25, 2025 02:02
@astral-sh-bot

astral-sh-bot Bot commented Nov 25, 2025 •

Copy link
Copy Markdown

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@MichaReiser MichaReiser left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should add some tests now. check_path is called from our testing framework, meaning we should now be able to write a test similar to

#[test]
fn noqa() -> Result<()> {
let diagnostics = test_path(
Path::new("ruff/noqa.py"),
&settings::LinterSettings::for_rules(vec![
Rule::UnusedVariable,
Rule::AmbiguousVariableName,
]),
)?;
assert_diagnostics!(diagnostics);
Ok(())
}

This could also be used as a replacement for some of the tests I asked for in your previous PR.

I also suggest adding some CLI tests verifying that this PR doesn't break in combination with --add-noqa, --remove-noqa --ignore-noqa etc.

Comment thread crates/ruff_linter/src/linter.rs
Comment thread crates/ruff_linter/src/linter.rs Outdated
@MichaReiser MichaReiser added the suppression Related to supression of violations e.g. noqa label Nov 25, 2025
Comment thread crates/ruff_linter/src/suppression.rs Outdated
@amyreese
amyreese force-pushed the amy/suppress-diagnostics branch from 850398d to 2ff32de Compare November 26, 2025 01:36
@MichaReiser MichaReiser changed the title [ruff] apply range suppressions to filter diagnostics apply range suppressions to filter diagnostics Nov 26, 2025
@MichaReiser MichaReiser added the internal An internal refactor or improvement (not for changelogs) label Nov 26, 2025
@amyreese
amyreese force-pushed the suppression-parsing branch from ce14617 to 607325e Compare December 1, 2025 21:17
@amyreese

amyreese commented Dec 2, 2025

Copy link
Copy Markdown
Contributor Author

I also suggest adding some CLI tests verifying that this PR doesn't break in combination with --add-noqa, --remove-noqa --ignore-noqa etc.

Is there an existing set of CLI tests for noqa that I can use as an example here?

@amyreese
amyreese force-pushed the amy/suppress-diagnostics branch from 2ff32de to 1586572 Compare December 2, 2025 01:30
@amyreese
amyreese requested a review from MichaReiser December 2, 2025 01:31
@MichaReiser

Copy link
Copy Markdown
Member

Is there an existing set of CLI tests for noqa that I can use as an example here?

There are some here

fn add_noqa() -> Result<()> {

I couldn't find any for --ignore-noqa, and --remove-noqa doesn't exist, it's just fix and you can find some tests in the above mentioned test file

@MichaReiser MichaReiser left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good. But we should look into the performance regression before landing this PR (can be fixed as a separate PR but we can't land this until we fixed the regression)

Comment thread crates/ruff_linter/resources/test/fixtures/ruff/suppressions.py Outdated
Comment thread crates/ruff_linter/resources/test/fixtures/ruff/suppressions.py Outdated
Comment thread crates/ruff_linter/resources/test/fixtures/ruff/suppressions.py Outdated
@amyreese

amyreese commented Dec 2, 2025

Copy link
Copy Markdown
Contributor Author

Note: add --preview gating so we can land this without waiting for diagnostics etc

@amyreese
amyreese force-pushed the suppression-parsing branch from ea5b48d to 288d431 Compare December 2, 2025 22:46
Base automatically changed from suppression-parsing to main December 2, 2025 23:40
@amyreese
amyreese force-pushed the amy/suppress-diagnostics branch from 1586572 to 5ebadd4 Compare December 3, 2025 02:03
Comment on lines +1743 to +1744
let test_code =
fs::read_to_string(fixture.root().join("noqa.py")).expect("should read test file");

@MichaReiser MichaReiser Dec 4, 2025 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We try to avoid reading fixture files in CLI tests as it makes the tests depend on each other and it can also become harder to reason about what we're testing here. Would it be possible to extract the specific case you want to test from noqa.py?

The tests here also don't need to be exhaustive. We can add more exhaustive tests to add_noqa (I think we have some integration tests, right?)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a copy-paste of the tests directly above and below it that exercise --add-noqa.

Comment thread crates/ruff_linter/src/linter.rs Outdated
Comment thread crates/ruff_linter/src/noqa.rs Outdated
])
.with_preview_mode(),
)?;
assert_diagnostics!(diagnostics);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be a good case for assert_diagnostics_diff which snapshots the difference between two settings: E.g. between preview on and off

@amyreese
amyreese merged commit 4e67a21 into main Dec 9, 2025
37 checks passed
@amyreese
amyreese deleted the amy/suppress-diagnostics branch December 9, 2025 00:12
dcreager added a commit that referenced this pull request Dec 9, 2025
…return

* dcreager/die-die-intersections: (29 commits)
  simpler bounds
  [`pylint`] Detect subclasses of builtin exceptions (`PLW0133`) (#21382)
  Fix stack overflow with recursive generic protocols (depth limit) (#21858)
  New diagnostics for unused range suppressions (#21783)
  [ty] Use default settings in completion tests
  [ty] Infer type variables within generic unions  (#21862)
  [ty] Fix overload filtering to prefer more "precise" match (#21859)
  [ty] Stabilize auto-import
  [ty] Fix reveal-type E2E test (#21865)
  [ty] Use concise message for LSP clients not supporting related diagnostic information (#21850)
  Include more details in Tokens 'offset is inside token' panic message (#21860)
  apply range suppressions to filter diagnostics (#21623)
  [ty] followup: add-import action for `reveal_type` too (#21668)
  [ty] Enrich function argument auto-complete suggestions with annotated types
  [ty] Add autocomplete suggestions for function arguments
  [`flake8-bugbear`] Accept immutable slice default arguments (`B008`) (#21823)
  [`pydocstyle`] Suppress `D417` for parameters with `Unpack` annotations (#21816)
  [ty] Remove legacy `concise_message` fallback behavior (#21847)
  [ty] Make Python-version subdiagnostics less verbose (#21849)
  [ty] Supress inlay hints when assigning a trivial initializer call (#21848)
  ...
dcreager added a commit that referenced this pull request Dec 9, 2025
…return

* dcreager/die-die-intersections: (31 commits)
  clippy
  reword comment
  simpler bounds
  [`pylint`] Detect subclasses of builtin exceptions (`PLW0133`) (#21382)
  Fix stack overflow with recursive generic protocols (depth limit) (#21858)
  New diagnostics for unused range suppressions (#21783)
  [ty] Use default settings in completion tests
  [ty] Infer type variables within generic unions  (#21862)
  [ty] Fix overload filtering to prefer more "precise" match (#21859)
  [ty] Stabilize auto-import
  [ty] Fix reveal-type E2E test (#21865)
  [ty] Use concise message for LSP clients not supporting related diagnostic information (#21850)
  Include more details in Tokens 'offset is inside token' panic message (#21860)
  apply range suppressions to filter diagnostics (#21623)
  [ty] followup: add-import action for `reveal_type` too (#21668)
  [ty] Enrich function argument auto-complete suggestions with annotated types
  [ty] Add autocomplete suggestions for function arguments
  [`flake8-bugbear`] Accept immutable slice default arguments (`B008`) (#21823)
  [`pydocstyle`] Suppress `D417` for parameters with `Unpack` annotations (#21816)
  [ty] Remove legacy `concise_message` fallback behavior (#21847)
  ...
dcreager added a commit that referenced this pull request Dec 9, 2025
…return

* dcreager/die-die-intersections: (31 commits)
  clippy
  reword comment
  simpler bounds
  [`pylint`] Detect subclasses of builtin exceptions (`PLW0133`) (#21382)
  Fix stack overflow with recursive generic protocols (depth limit) (#21858)
  New diagnostics for unused range suppressions (#21783)
  [ty] Use default settings in completion tests
  [ty] Infer type variables within generic unions  (#21862)
  [ty] Fix overload filtering to prefer more "precise" match (#21859)
  [ty] Stabilize auto-import
  [ty] Fix reveal-type E2E test (#21865)
  [ty] Use concise message for LSP clients not supporting related diagnostic information (#21850)
  Include more details in Tokens 'offset is inside token' panic message (#21860)
  apply range suppressions to filter diagnostics (#21623)
  [ty] followup: add-import action for `reveal_type` too (#21668)
  [ty] Enrich function argument auto-complete suggestions with annotated types
  [ty] Add autocomplete suggestions for function arguments
  [`flake8-bugbear`] Accept immutable slice default arguments (`B008`) (#21823)
  [`pydocstyle`] Suppress `D417` for parameters with `Unpack` annotations (#21816)
  [ty] Remove legacy `concise_message` fallback behavior (#21847)
  ...
dcreager added a commit that referenced this pull request Dec 10, 2025
* origin/main: (33 commits)
  [ty] Simplify union lower bounds and intersection upper bounds in constraint sets (#21871)
  [ty] Collapse `never` paths in constraint set BDDs (#21880)
  Fix leading comment formatting for lambdas with multiple parameters (#21879)
  [ty] Type inference for `@asynccontextmanager` (#21876)
  Fix comment placement in lambda parameters (#21868)
  [`pylint`] Detect subclasses of builtin exceptions (`PLW0133`) (#21382)
  Fix stack overflow with recursive generic protocols (depth limit) (#21858)
  New diagnostics for unused range suppressions (#21783)
  [ty] Use default settings in completion tests
  [ty] Infer type variables within generic unions  (#21862)
  [ty] Fix overload filtering to prefer more "precise" match (#21859)
  [ty] Stabilize auto-import
  [ty] Fix reveal-type E2E test (#21865)
  [ty] Use concise message for LSP clients not supporting related diagnostic information (#21850)
  Include more details in Tokens 'offset is inside token' panic message (#21860)
  apply range suppressions to filter diagnostics (#21623)
  [ty] followup: add-import action for `reveal_type` too (#21668)
  [ty] Enrich function argument auto-complete suggestions with annotated types
  [ty] Add autocomplete suggestions for function arguments
  [`flake8-bugbear`] Accept immutable slice default arguments (`B008`) (#21823)
  ...
ntBre added a commit that referenced this pull request Jan 30, 2026
Added in #21623. I think I caught
everything, including the preview reference in the linter docs, but hopefully
@amyreese will remember anything else I missed.
ntBre added a commit that referenced this pull request Jan 30, 2026
Added in #21623. 

I think I caught everything, including the preview reference in the
linter docs, but hopefully @amyreese will remember anything else I
missed.
ntBre added a commit that referenced this pull request Feb 3, 2026
Added in #21623. 

I think I caught everything, including the preview reference in the
linter docs, but hopefully @amyreese will remember anything else I
missed.
ntBre added a commit that referenced this pull request Feb 3, 2026
Added in #21623. 

I think I caught everything, including the preview reference in the
linter docs, but hopefully @amyreese will remember anything else I
missed.
KotlinIsland pushed a commit to KotlinIsland/basedpython that referenced this pull request May 1, 2026
Added in astral-sh/ruff#21623. 

I think I caught everything, including the preview reference in the
linter docs, but hopefully @amyreese will remember anything else I
missed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

internal An internal refactor or improvement (not for changelogs) suppression Related to supression of violations e.g. noqa

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants