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

Pre-commit hook with --remove-all-unused-imports always passes #277

Closed
rob-levy-minimum opened this issue Sep 21, 2023 · 2 comments · Fixed by #278
Closed

Pre-commit hook with --remove-all-unused-imports always passes #277

rob-levy-minimum opened this issue Sep 21, 2023 · 2 comments · Fixed by #278

Comments

@rob-levy-minimum
Copy link

rob-levy-minimum commented Sep 21, 2023

If you specify --remove-all-unused-imports in the args section of .pre-commit.yaml then the hook always passes, even when you have unused imports.

Case study

.pre-commit.yaml

repos:
  - repo: https://github.com/PyCQA/autoflake
    rev: v2.2.1
    hooks:
      - id: autoflake
        args: [--remove-all-unused-imports]

foo.py

import random

print("Does nothing")

Try commiting foo.py and the hook will pass!

If I remove the arg then the hook works as expected.

It works as expected when running from the command line:

$ autoflake --remove-all-unused-imports foo.py
--- original/foo.py
+++ fixed/foo.py
@@ -1,3 +1,2 @@
-import random

 print("Does nothing")
@fsouza
Copy link
Collaborator

fsouza commented Sep 22, 2023

@rob-levy-minimum does adding --in-place fix it? I wonder if there's a way for us to detect that we're being invoked by pre-commit and change the default value for for that flag.

@rob-levy-minimum
Copy link
Author

Oh nice. Adding --in-place makes it work! Maybe just add it to the README describing how to set it up as a hook, that's all that's required I'd say.

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 a pull request may close this issue.

2 participants