You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Running hatch fmt can move noqa comments to the wrong line when line-splitting. This caused me additional confusion because a second run of the formatter removed the now-extraneous noqa, and started showing me errors again.
Here is a minimal reproducer, used in a clean hatch new project. The first run of hatch fmt will reformat and return no other errors, but will split the noqa to the wrong line. A second run of hatch fmt will then strip the "invalid" noqa and start showing errors again.
def main():
some_list = [1, 2, 3]
another_list = []
if True:
if True:
for item in some_list:
another_list.append(generate_item( # noqa: PERF401 # Personal preference
item=item,
stuff=1))
def generate_item(item, stuff):
return item + stuff
Personally, the biggest usability issue for me was that the first fmt run returned no errors - I usually assume the code would be stable after a run of fmt with no errors.
Hatch version: 1.14.0
The text was updated successfully, but these errors were encountered:
hatch fmt uses ruff as backend, running first the linter and then the formatter. Similar behavior can be reproduced using plain ruff:
$ ruff version
ruff 0.11.0
$ ruff check --select PERF401 .
All checks passed!
$ ruff format .
1 file reformatted, 4 files left unchanged
$ ruff check --select PERF401 .
testing/src/testing/__main__.py:11:17: PERF401 Use `list.extend` to create a transformed list
|
9 |if True:
10 |foritemin some_list:
11 | / another_list.append(
12 || generate_item( # noqa: PERF401 # Personal preference
13 || item=item, stuff=1
14 || )
15 || )
||_________________^ PERF401
|
= help: Replace for loop with list.extend
Found 1 error.
I think this is rather a ruff problem and not much a hatch problem. The reason is that the formatter breaks the line, moves the comment and then it no longer targets the correct line.
I do not think there is a good solution to this problem from the hatch side.
Running
hatch fmt
can move noqa comments to the wrong line when line-splitting. This caused me additional confusion because a second run of the formatter removed the now-extraneous noqa, and started showing me errors again.Here is a minimal reproducer, used in a clean
hatch new
project. The first run ofhatch fmt
will reformat and return no other errors, but will split the noqa to the wrong line. A second run ofhatch fmt
will then strip the "invalid" noqa and start showing errors again.Personally, the biggest usability issue for me was that the first fmt run returned no errors - I usually assume the code would be stable after a run of fmt with no errors.
Hatch version: 1.14.0
The text was updated successfully, but these errors were encountered: