hatch icon indicating copy to clipboard operation
hatch copied to clipboard

fix: show what has changed when running hatch fmt

Open henryiii opened this issue 1 year ago • 5 comments

For some reason, Ruff just makes changes without telling the user why it's changing things by default. Adding --show-fixes prints a nice summary of what's changed.

henryiii avatar Jun 13 '24 15:06 henryiii

Does the formatter also have such an option?

ofek avatar Jun 13 '24 15:06 ofek

No, because it's not made of (public?) rules like the linter is.

henryiii avatar Jun 13 '24 15:06 henryiii

Sorry I didn't test what the output looks like with that flag but my assumption was that it would show the diff in addition to fixing, is not the case? I can't check right now.

ofek avatar Jun 13 '24 15:06 ofek

Before:

cmd [1] | ruff check --config /home/henryfs/.local/share/hatch/env/.internal/hatch-static-analysis/.config/2ZdIY43U/pyproject.toml --fix hackathon/jax_nbody.py
hackathon/jax_nbody.py:1:1: INP001 File `hackathon/jax_nbody.py` is part of an implicit namespace package. Add an `__init__.py`.
hackathon/jax_nbody.py:45:1: E402 Module level import not at top of file
hackathon/jax_nbody.py:46:1: E402 Module level import not at top of file
hackathon/jax_nbody.py:52:75: N803 Argument name `G` should be lowercase
hackathon/jax_nbody.py:87:55: COM818 Trailing comma on bare tuple prohibited
hackathon/jax_nbody.py:89:53: FBT002 Boolean default positional argument in function definition
hackathon/jax_nbody.py:89:53: ARG001 Unused function argument: `verbose`
hackathon/jax_nbody.py:91:5: N806 Variable `G` in function should be lowercase
hackathon/jax_nbody.py:99:5: F841 Local variable `number_particles` is assigned to but never used
hackathon/jax_nbody.py:138:5: N806 Variable `N` in function should be lowercase
hackathon/jax_nbody.py:139:5: N806 Variable `STEPS` in function should be lowercase
hackathon/jax_nbody.py:145:13: N806 Variable `N` in function should be lowercase
hackathon/jax_nbody.py:181:13: F841 Local variable `jitted_sim` is assigned to but never used
hackathon/jax_nbody.py:190:13: T201 `print` found
Found 52 errors (38 fixed, 14 remaining).
No fixes available (3 hidden fixes can be enabled with the `--unsafe-fixes` option).

After:

cmd [1] | ruff check --config /home/henryfs/.local/share/hatch/env/.internal/hatch-static-analysis/.config/2ZdIY43U/pyproject.toml --fix hackathon/jax_nbody.py --show-fixes
hackathon/jax_nbody.py:1:1: INP001 File `hackathon/jax_nbody.py` is part of an implicit namespace package. Add an `__init__.py`.
hackathon/jax_nbody.py:45:1: E402 Module level import not at top of file
hackathon/jax_nbody.py:46:1: E402 Module level import not at top of file
hackathon/jax_nbody.py:52:75: N803 Argument name `G` should be lowercase
hackathon/jax_nbody.py:87:55: COM818 Trailing comma on bare tuple prohibited
hackathon/jax_nbody.py:89:53: FBT002 Boolean default positional argument in function definition
hackathon/jax_nbody.py:89:53: ARG001 Unused function argument: `verbose`
hackathon/jax_nbody.py:91:5: N806 Variable `G` in function should be lowercase
hackathon/jax_nbody.py:99:5: F841 Local variable `number_particles` is assigned to but never used
hackathon/jax_nbody.py:138:5: N806 Variable `N` in function should be lowercase
hackathon/jax_nbody.py:139:5: N806 Variable `STEPS` in function should be lowercase
hackathon/jax_nbody.py:145:13: N806 Variable `N` in function should be lowercase
hackathon/jax_nbody.py:181:13: F841 Local variable `jitted_sim` is assigned to but never used
hackathon/jax_nbody.py:190:13: T201 `print` found

Fixed 38 errors:
- hackathon/jax_nbody.py:
    20 × W293 (blank-line-with-whitespace)
     8 × F401 (unused-import)
     4 × W291 (trailing-whitespace)
     3 × I001 (unsorted-imports)
     1 × UP032 (f-string)
     1 × PLR1711 (useless-return)
     1 × PLR0402 (manual-from-import)

Found 52 errors (38 fixed, 14 remaining).
No fixes available (3 hidden fixes can be enabled with the `--unsafe-fixes` option).

henryiii avatar Jun 13 '24 16:06 henryiii

Interesting, I wonder if there is a feature request for the formatter that essentially just outputs the diff in addition to performing it.

ofek avatar Jun 13 '24 16:06 ofek