peterjc / flake8-black

flake8 plugin to run black for checking Python coding style
MIT License
166 stars 10 forks source link

flake8-black should display full black diff #30

Closed girst closed 3 years ago

girst commented 3 years ago

Our CI and my local machine have different versions of python/flake8/black/flake8-black installed. Hence, when trying to make it pass on the CI, I cannot reproduce the diff locally. looking at the logs only shows the position of the first change in the file. Not only does this require trial-and-error on what exactly black wants, but it has to be repeated multiple times, since only the first change per file is shown.

if flake8-black were to print the full diff, not only would all linting errors show up at once, but it would also make clear what changes black wants.

peterjc commented 3 years ago

Printing out the diff would break with flake8 conventions, so no.

if you want the diff, just use ‘black —check —diff ...’ instead (no need for flake8 or this plugin).

If black alone and flake8-black give different results, this is most likely due to different versions of black. Double check they are using the same copy of black (having more than one copy of python is common, eg virtual environments). Set the desired version of black explicitly in your requirements.txt or other configuration as needed?

If you still see differences, are you using any non default black settings?

girst commented 3 years ago

Printing out the diff would break with flake8 conventions, so no.

fair enough, and thanks for the quick reply. i'll raise the other points to the appropriate people ;)

still, that flake8-black only shows one BLK100 per file is suboptimal. other flake8 errors are very descriptive, and each occurrence is shown in the log, so it's possible to fix them straight from the CI output.

peterjc commented 3 years ago

When I wrote flake8-black, I found little value in reporting multiple flake8 messages per file - it was typically too noisy, and in any case the fix was typically just run black on the file anyway. If you are manually fixing individual lines, then I can see why you might prefer that.

Alternatively, you may want to look into running the tool pre-commit for calling flake8, black, and various other checks as a git pre-commit hook and/or on your continuous integration? Don't be mislead by the tool's name - it is much broader in scope: https://github.com/pre-commit/pre-commit