autoflake icon indicating copy to clipboard operation
autoflake copied to clipboard

autoflake seems to exit 0 even if a diff is produced

Open discentem opened this issue 2 years ago • 2 comments

% /path/to/python3 -m autoflake ~/autoflake_test --remove-all-unused-imports --remove-unused-variables -r --exclude whatever/*
--- original//Users/brandon/autoflake_test/test.py
+++ fixed//Users/brandon/autoflake_test/test.py
@@ -1,3 +1,3 @@
 def main(): 
-       thing = "blah"
+       pass
 main()
--- original//Users/brandon/autoflake_test/test2.py
+++ fixed//Users/brandon/autoflake_test/test2.py
@@ -1,3 +1,3 @@
 def main():
-       thing = "blah"
+       pass
 main()
% echo $?               
0

This makes it harder to run in CI because it's not exiting zero. What's the intended behavior here?

discentem avatar Jun 25 '22 22:06 discentem

-c, --check           return error code if changes are needed

pukkandan avatar Jul 07 '22 06:07 pukkandan

-m autoflake ~/autoflake_test --remove-all-unused-imports --remove-unused-variables -r --exclude whatever/*

If -c is used, the diff is suppressed. So this would make CI fail but would make it harder to know why. :/

Would you consider a bug that -c causes the diff to get suppressed?

discentem avatar Jul 16 '22 19:07 discentem

+1. Ideally -c should print the diff to stdout. An alternative could be a flag which toggles diff view or the condensed view that -c defaults to now.

ericstengard avatar Sep 22 '22 11:09 ericstengard

@fsouza is there a requirement to keep backwards compatibility? Otherwise I'd propose that --check spits out the diff as well. If we need backwards compatibility maybe another keyword should be introduced which makes --check print diffs?

I'm able to fix it either way but I'd appreciate your input first.

ericstengard avatar Sep 29 '22 10:09 ericstengard

@ericstengard can we do that via a new flag? This way we can keep backwards compatibility.

fsouza avatar Oct 03 '22 12:10 fsouza

@ericstengard can we do that via a new flag? This way we can keep backwards compatibility.

Yes I'd say that it's fine. I'm thinking something like --check-verbose or --check-diff since --check by default makes it less verbose. I'm leaning more towards --check-diff.

ericstengard avatar Oct 03 '22 13:10 ericstengard