Implement #ruff:file-ignore file-level suppressions#23599
Conversation
#ruff:ignore-all range suppressions#ruff:ignore-all file-level suppressions
|
| # ruff: ignore-all[F401, ARG001] | ||
| ``` | ||
|
|
||
| The full-level suppression comment specification is as follows: |
There was a problem hiding this comment.
| The full-level suppression comment specification is as follows: | |
| The full file-level suppression comment specification is as follows: |
I think
dylwil3
left a comment
There was a problem hiding this comment.
I think this is a great idea! Especially because users have reported accidentally doing ruff: noqa: code when they meant to just do noqa: code. So I think eventually we should deprecate the ruff: noqa: code option in favor of this one.
One question I have is whether we want to take this opportunity to be more stringent about the requirement that the file-level suppression be "towards the top". Maybe before any code? (possibly excluding module-level docstrings)?
It always seemed strange to me that someone could stick # ruff: noqa: code randomly in the middle of the file and it would affect the whole file.
I thought about this as well, but I guess it could be a separate lint rule or something as an alternative. |
c9df742 to
aef5860
Compare
7bce278 to
dfb0d89
Compare
MichaReiser
left a comment
There was a problem hiding this comment.
We'll need to update is_pragma_comment to recognize the new pragma comments that this PR and the ruff: ignore PR add.
That function already recognizes all comments starting with |
aef5860 to
d03c94e
Compare
dfb0d89 to
64ca042
Compare
d03c94e to
fdfae04
Compare
20cf527 to
3cb3a2f
Compare
7089290 to
029f481
Compare
64ca042 to
f87a79a
Compare
8298523 to
87d0adf
Compare
|
Rebased, ensured suppressions are sorted by |
|
Coming back to this and not remembering what this PR was about, I misinterpreted the PR title as meaning this PR introduces
|
|
For reference, Biome uses |
I could see us allowing this in the future (using categories in suppressions). It's something I find useful in clippy, specifically at the file level. |
f1d6b14 to
0ba1467
Compare
#ruff:ignore-all file-level suppressions#ruff:file-ignore file-level suppressions
|
Updated to use |
| } | ||
| } else { | ||
| warn_user_once!( | ||
| "#ruff:file-ignore comment found but not active, enable preview mode" |
There was a problem hiding this comment.
| "#ruff:file-ignore comment found but not active, enable preview mode" | |
| "#ruff:file-ignore comment found but has no effect, enable preview mode" |
There was a problem hiding this comment.
I'm not fond of "has no effect" because it seems to imply that it's "unused", ie, doesn't suppress anything, rather than it being ignored by Ruff because it's not running in preview mode... 🤔
There was a problem hiding this comment.
Also this matches what we already used for #ruff:ignore
| covered_source: "# ruff: disable[bar]\n print('hello')\n\n", | ||
| code: "bar", | ||
| covered_source: "# ruff: disable[foo]\nprint('hello')\n\ndef foo():\n # ruff: disable[bar]\n print('hello')\n\n", | ||
| code: "foo", |
There was a problem hiding this comment.
did these snapshots change just because of the ordering change? (I think so but just making sure I'm not missing something)
There was a problem hiding this comment.
Yes, this is because the sorting changed the order of the suppressions in the snapshots, and so the diff is a bit weird.
| def bar(self, arg1, arg2): | ||
| print("hello") | ||
|
|
||
| # ruff: file-ignore[ARG002] should cover the class method above! |
There was a problem hiding this comment.
This is a bit tricky, and I can see an argument in both directions:
- Marking the inline comment as unused has the advantage that it reduces the total number of suppressions.
- Marking the file-level suppression as unused has the advantage that it keeps suppressions as local as possible (unless the file-level suppression is used in at least one other place).
I wanted to argue that ty implements the second behavior, but it doesn't (https://play.ty.dev/47a21efb-d9e7-46f4-964e-69ff82bb5467). So I think this is fine.
* main: (248 commits) [ty] bump conformance suite commit (astral-sh#24848) [ty] Pass unmapped type variables to `SpecializationBuilder::build_with` (astral-sh#24809) [ty] Avoid bookkeeping for unannotated functions (astral-sh#24842) [ty] Optimize signature checking based on number of arguments (astral-sh#24674) [ty] Avoid eagerly inferring legacy generic context (astral-sh#24841) [ty] Skip decorator inference for undecorated functions (astral-sh#24839) [ty] solve unions against generic protocols (astral-sh#24837) [ty] Lazily allocate parameter type builders (astral-sh#24838) [ty] Lazily compute call argument fallbacks (astral-sh#24836) [ty] Avoid collecting type context callables (astral-sh#24835) Bump ecosystem-analyzer to e7576e6 (astral-sh#24834) [ty] Support basic narrowing with aliased conditional expressions (astral-sh#24302) [ty] Fix project and workspace selection (astral-sh#24824) [ty] Fix missing memory usage attributes (astral-sh#24823) Fix setting selection for multi folder workspace (astral-sh#24819) Improve diagnostics for implicit calls to a possibly unbound unary operator. (astral-sh#24816) [ty] Update review pool (astral-sh#24818) Bump 0.15.12 (astral-sh#24815) [ty] Complete support for more detailed diagnostics on possibly unbound errors from implicit dunder calls against unions. (astral-sh#24676) Implement `#ruff:file-ignore` file-level suppressions (astral-sh#23599) ...
Follow-up to #23404
Add support for
#ruff:file-ignore[code]style file-level suppressionsas own-line comments at global module scope. The range covered by these
suppressions is always the entirety of the file:
This currently requires having preview mode enabled. Without preview mode,
the comments are parsed and processed, but not materialized into active
suppressions at runtime.