psf / black

The uncompromising Python code formatter
https://black.readthedocs.io/en/stable/
MIT License
38.81k stars 2.45k forks source link

Additional sanity checks #3429

Open JelleZijlstra opened 1 year ago

JelleZijlstra commented 1 year ago

Currently, Black checks that the AST of its input and output is the same (except for some narrow exceptions). This is a powerful feature that has caught many bugs (e.g. most recently #3428).

Could we add more similar checks?

The downside of adding more safety checks is that it will make Black slower. But if users want speed over safety, they can use --fast already, so if the overhead of a comment equivalence check isn't too bad, I think we should do it.

felix-hilden commented 1 year ago

Yeah could be nice 👌 For line length, we could perhaps consider the non-whitespace portion only. For a given line in a diff, we know the post-formatting indentation and could then compare the line length that it would've produced. Splits would be harder though. Or we could indent in another pass since it's such a fundamental formatting move :P (perhaps let's not)