astral-sh / ruff

An extremely fast Python linter and code formatter, written in Rust.
https://docs.astral.sh/ruff
MIT License
33k stars 1.1k forks source link

`redirected-noqa` (`RUF101`) does not detect file-level `# ruff: noqa` comments #14531

Open AlexWaygood opened 8 hours ago

AlexWaygood commented 8 hours ago

Ruff supports file-level noqa comments: # ruff: noqa: TC002 on its own line at the top of a file will lead to the TC002 code being suppressed for the whole file. RUF101, however, appears not to detect these file-level comments when it looks for redirected rule codes; it only flags inline noqa comments of the form # noqa: TCH001.

For example, I would expect Ruff to emit a RUF101 diagnostic on the first line of this snippet, since Ruff's flake8-type-checking rules have been recoded from TCH to TC. However, no RUF101 diagnostic is emitted:

# ruff: noqa: TCH002

from __future__ import annotations

import local_module

def func(sized: local_module.Container) -> int:
    return len(sized)

https://play.ruff.rs/26c8939c-fc09-4d85-a25c-f80bea97a842