Skip to content

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

@rob-levy-minimum

Description

@rob-levy-minimum

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions