Skip to content

--add-noqa deletes trailing content #26287

Description

@ntBre

Another problem encountered while working on --add-ignore:

$ cat try.py
import math  # noqa: RUF100 with a trailing reason
import sys  # noqa: RUF100 # fmt:skip
$ ruff check --add-noqa
Added 2 noqa directives.
$ cat try.py
import math  # noqa: F401, RUF100
import sys  # noqa: F401, RUF100

I'm surprised this one hasn't been reported before, at least as far as Codex and I found.

ty handles this nicely:

$ cat ty.py
value = missing  # ty:ignore[division-by-zero]  # fmt: skip
$ uvx ty check --add-ignore ty.py
Added 1 ignore comment
$ cat ty.py
value = missing  # ty:ignore[division-by-zero, unresolved-reference]  # fmt: skip
$ cat ty.py
value = 1/0  # ty:ignore[division-by-zero]  a reason
$ uvx ty check --add-ignore ty.py
Added 1 ignore comment
$ cat ty.py
value = missing  # ty:ignore[division-by-zero]  a reason  # ty:ignore[unresolved-reference]

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingsuppressionRelated to supression of violations e.g. noqa

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions