PHG004: Potential regression
- Dominant language
- Rust
- Stars
- 49.6k
- Forks
- 2.4k
- Avg merge
- 2d 1h
- Merged PRs (30d)
- 458
Description
Recently on updating Ruff, I started getting ``PGH004`` errors for a paragraph comment describing ``#noqa`` handling [^1]. I've attached a minimal reproducer below; the errors started appearing in Ruff 0.0.281 and a warning which previously appeared is now absent in Ruff 0.0.284.
My suggested remedy would be to only match a ``noqa`` comment if there are only whitespace tokens between the comment marker and the ``noqa`` token.
A
```python
# A sentence talking about using #noqa in prose.
# A new sentence talking about using #noqa.
# A third sentence talking about using #noqa
```
```console
$ pip install "ruff==0.0.280" --quiet
$ ruff check pgh004.py --isolated --select PGH004
$ pip install "ruff==0.0.281" --quiet
$ ruff check pgh004.py --isolated --select PGH004
warning: Invalid `# noqa` directive on pgh004.py:2: expected `:` followed by a comma-separated list of codes (e.g., `# noqa: F401, F841`).
pgh004.py:1:34: PGH004 Use specific rule codes when using `noqa`
pgh004.py:3:40: PGH004 Use specific rule codes when using `noqa`
Found 2 errors.
$ pip install "ruff==0.0.284" --quiet
$ ruff check pgh004.py --isolated --select PGH004
pgh004.py:1:34: PGH004 Use specific rule codes when using `noqa`
pgh004.py:3:40: PGH004 Use specific rule codes when using `noqa`
Found 2 errors.
```
[^1]: The specific pararaph is:
# There is no point in having #noqa on literal blocks because
# they cannot contain references. Recognizing it would just
# completely prevent escaping the #noqa. Outside of literal
# blocks, one can always write \#noqa.
Contributor guide
Research direction
Start by reproducing the report with the pgh004.py example and the Ruff 0.0.280, 0.0.281, and 0.0.284 commands. Trace the PGH004 noqa matching behavior, then verify that prose mentioning #noqa is not matched unless only whitespace separates the comment marker and token, while actual noqa handling still works.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100