ruff: ERA001: autofix removes valid comments that do not contain code or removes not everything
Example:
# Example of headers:
# X-token: <token_id>
# X-scope: no-scope
# End of comment about headers
# {
# "some-key": {
# '1': 1,
# '2': 2',
# }
# }
# some = 1
# awesome = 2
#
# foobar = 3
# barfoo = 4
# example code from IPython:
# In [20]: parse.parse_qsl('&l=55.123;123.1&count=3', keep_blank_values=1)
# Out[20]: [('l', '55.123'), ('123.1', ''), ('count', '3')]
# End of comment
# (пример, пример2) = (example1, example2)
# if not success: # TODO: comment
# errors.append('Ошибка: error')
# comment
# 1. [{пример первый}]
# 2. [[пример]]
# 3. [] - пусто
# Пример: {"description": "weight: "}
# comment about calculation
# 100 / 2 = 50
# end of comment
# comment:
# - tuple: ()
# - list: []
# - set: set()
# - dict: {}
# example of output:
# 'OK: message sent. Message-ID: 123456'
# MySQL: enum('positive', 'negative')
# query: lock + user.id
Ruff output:
$ ruff --fix --select ERA001 ruff_errors/ERA001.py
Found 24 errors (24 fixed, 0 remaining).
Contents of the file after fix:
# Example of headers:
# X-token: <token_id>
# End of comment about headers
# "some-key": {
#
# example code from IPython:
# End of comment
# if not success: # TODO: comment
# comment
# 1. [{пример первый}]
# 3. [] - пусто
# comment about calculation
# end of comment
# comment:
# example of output:
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 19 (16 by maintainers)
Commits related to this issue
- Update CLI to respect fix applicability (#7769) Rebase of https://github.com/astral-sh/ruff/pull/5119 authored by @evanrittenhouse with additional refinements. ## Changes - Adds `--unsafe-fixe... — committed to astral-sh/ruff by zanieb 3 years ago
- Update CLI to respect fix applicability (#7769) Rebase of https://github.com/astral-sh/ruff/pull/5119 authored by @evanrittenhouse with additional refinements. ## Changes - Adds `--unsafe-fixe... — committed to astral-sh/ruff by zanieb 3 years ago
Is there scope for a PR for better algorithms, and a better set of false positive rules here?
It will deviate from the eradicate plugin, would that be okay or should it be a different rule entirely then?
I don’t think we’re in a position to improve this much, the logic itself is derived from eradicate, and I’d bet eradicate has the same or very similar behavior. Perhaps we should remove the autofix from this rule though. It seems correct to flag that there’s some commented-out code here, but rely on users to remove it.
Alternatively, we could only autofix if all lines in a comment block are identified as code.
this is the comment I wrote, it contains
returnin this sentence only because of that, it is raising a warning@jaap3 - Funnily enough that specific case was reported recently and is fixed on
main.We’ve updated the applicability of the fix here to “Manual” which will never automatically apply once we merge #5119 — I don’t think there’s more to do here this issue will be resolved once applicability is respected by the CLI per https://github.com/astral-sh/ruff/issues/4185
I like
Perhaps we could use
Suggestedin that case andManualotherwise?