Skip to content

Conversation

@MichaReiser
Copy link
Member

@MichaReiser MichaReiser commented Dec 20, 2024

Summary

This PR implements a new Red Knot rule that reports unused type: ignore or knot: ignore[code] comments.

The tricky part about this rule is that unused-ignore-comment can itself be suppressed by using an ignore comment.
Ruff only supports suppressing unused-noqa warnings with a file-level noqa comment. Unfortunately, we
don't support file-level ignore comments other than type: ignore but we also want to warn about unused
file-level type: ignore comments.

That's why this PR proposes that we allow suppressing unused-ignore-comment but only by using knot: ignore[unused-ignore-comment].

Open questions

Ruff calls the rule unused-noqa, but I'm not sure if unnecessary or useless would be more fitting because you can't use an ignore code. But an ignore code can be useless (or unnecessary).

Test Plan

Added mdtests

@MichaReiser MichaReiser force-pushed the micha/unused-ignore-comment branch from 37868f8 to dbdbd8d Compare December 20, 2024 16:28
@MichaReiser MichaReiser added the ty Multi-file analysis & type inference label Dec 20, 2024
@MichaReiser MichaReiser force-pushed the micha/unused-ignore-comment branch 2 times, most recently from 6ea4bfa to 1255dc7 Compare December 20, 2024 16:31
@github-actions
Copy link
Contributor

github-actions bot commented Dec 20, 2024

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@MichaReiser MichaReiser marked this pull request as ready for review December 20, 2024 17:15
@MichaReiser MichaReiser force-pushed the micha/file-level-type-ignore branch from 357825e to ec700b8 Compare December 21, 2024 16:41
@MichaReiser MichaReiser force-pushed the micha/unused-ignore-comment branch from d83fc9b to b32e668 Compare December 21, 2024 16:42
@MichaReiser MichaReiser force-pushed the micha/file-level-type-ignore branch from ec700b8 to 788bfd2 Compare December 23, 2024 09:53
Base automatically changed from micha/file-level-type-ignore to main December 23, 2024 09:59
@MichaReiser MichaReiser force-pushed the micha/unused-ignore-comment branch 3 times, most recently from f5520be to 968741c Compare December 23, 2024 10:04
@MichaReiser MichaReiser force-pushed the micha/unused-ignore-comment branch from 968741c to 5a12efd Compare December 23, 2024 10:08
@MichaReiser MichaReiser merged commit 2a99c0b into main Dec 23, 2024
21 checks passed
@MichaReiser MichaReiser deleted the micha/unused-ignore-comment branch December 23, 2024 10:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants