Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: show what has changed when running hatch fmt #1567

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

henryiii
Copy link
Contributor

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.

@ofek
Copy link
Collaborator

ofek commented Jun 13, 2024

Does the formatter also have such an option?

@henryiii
Copy link
Contributor Author

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

@ofek
Copy link
Collaborator

ofek commented Jun 13, 2024

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.

@henryiii
Copy link
Contributor Author

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).

@ofek
Copy link
Collaborator

ofek commented Jun 13, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants