Skip to content

Match noqa shebang handling in ruff:ignore comments - #26286

Merged
ntBre merged 2 commits into
mainfrom
brent/ruff-ignore-shebang
Jun 24, 2026
Merged

Match noqa shebang handling in ruff:ignore comments#26286
ntBre merged 2 commits into
mainfrom
brent/ruff-ignore-shebang

Conversation

@ntBre

@ntBre ntBre commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Summary

This addresses another discrepancy Codex noticed between noqa and ruff:ignore while reviewing my
--add-ignore PR. noqa had special handling for shebang lines, which allowed it to suppress a
diagnostic with a 0..0 range, like D100, even when a shebang was present that prevented putting
the suppression on the first line:

 #!/usr/bin/python
 # noqa: D100

Playground

This was previously not the case for ruff:ignore.

 #!/usr/bin/python
 # ruff:ignore[D100]

Playground

Test Plan

A new mdtest covering this scenario

Summary
--

This addresses another discrepancy Codex noticed between `noqa` and `ruff:ignore` while reviewing my
`--add-ignore` PR. `noqa` had special handling for shebang lines, which allowed it to suppress a
diagnostic with a 0..0 range, like `D100`, even when a shebang was present that prevented putting
the suppression on the first line:

```py
 #!/usr/bin/python
 # noqa: D100
```

[Playground](https://play.ruff.rs/5381b897-06d1-4d41-900b-cc85a40b2740)

This was previously not the case for `ruff:ignore`.

```py
 #!/usr/bin/python
 # ruff:ignore[D100]
```

[Playground](https://play.ruff.rs/1d3dde25-2692-43f3-a6fb-54b2e156ba66)

Test Plan
--

A new mdtest covering this scenario
@ntBre ntBre added bug Something isn't working suppression Related to supression of violations e.g. noqa preview Related to preview mode features labels Jun 23, 2026
@astral-sh-bot

astral-sh-bot Bot commented Jun 23, 2026

Copy link
Copy Markdown

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

in the same section, this gets appended to the other code block and is no longer a shebang. in a
separate section, mdtest doesn't extract the trailing `# error` comment on the shebang line, so it's
impossible to assert that the error occurs
@ntBre
ntBre marked this pull request as ready for review June 23, 2026 22:43
@ntBre
ntBre requested a review from MichaReiser June 23, 2026 22:43
@ntBre
ntBre merged commit acc7a1b into main Jun 24, 2026
47 checks passed
@ntBre
ntBre deleted the brent/ruff-ignore-shebang branch June 24, 2026 14:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working preview Related to preview mode features suppression Related to supression of violations e.g. noqa

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants