Skip to content

Group unused range suppression codes into single diagnostic #21873

@amyreese

Description

@amyreese

Summary

If a range suppression has more than one unused code, ruff will produce a separate diagnostic for each unused code, rather than grouping them into a single diagnostic like will happen for unused noqa:

$ cat ~/scratch/ruff/foo.py
# ruff: disable[F401, F501]
print("hello")  # noqa: F401 F501
$ cargo run -p ruff -- check --no-cache --isolated --preview --select F,RUF100 ~/scratch/ruff/foo.py
RUF100 [*] Unused suppression (unused: `F401`)
 --> /Users/amethyst/scratch/ruff/foo.py:1:17
  |
1 | # ruff: disable[F401, F501]
  |                 ^^^^
2 | print("hello")  # noqa: F401 F501
  |
help: Remove unused suppression
  - # ruff: disable[F401, F501]
1 + # ruff: disable[F501]
2 | print("hello")  # noqa: F401 F501
3 |

RUF100 [*] Unused suppression (unused: `F501`)
 --> /Users/amethyst/scratch/ruff/foo.py:1:23
  |
1 | # ruff: disable[F401, F501]
  |                       ^^^^
2 | print("hello")  # noqa: F401 F501
  |
help: Remove unused suppression
  - # ruff: disable[F401, F501]
1 + # ruff: disable[F401]
2 | print("hello")  # noqa: F401 F501
3 |

RUF100 [*] Unused `noqa` directive (unused: `F401`, `F501`)
 --> /Users/amethyst/scratch/ruff/foo.py:2:17
  |
1 | # ruff: disable[F401, F501]
2 | print("hello")  # noqa: F401 F501
  |                 ^^^^^^^^^^^^^^^^^
  |
help: Remove unused `noqa` directive
1 | # ruff: disable[F401, F501]
  - print("hello")  # noqa: F401 F501
2 + print("hello")
3 |

Found 3 errors.
[*] 3 fixable with the `--fix` option.
> [1]

Version

No response

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingruleImplementing or modifying a lint rulesuppressionRelated to supression of violations e.g. noqa

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions