-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
format SCM diffs only #320
Comments
That goes against PEP 8 (consistency within a file) and the philosophy of Black. For adoption it's a better experience to create one sweeping commit that is easy to omit in We need a section of the docs that explains this. |
I see. I was thinking more along lines for projects that have no true one style, that already violates pep 8. |
You can always reformat the whole file, and discard irrelevant changes with |
I think that's a bad idea:
|
Black's reformatting is AST-safe; the AST resulting from parsing the reformatted code is identical to the AST prior to the reformat. Black checks and verifies this identity. Therefore, the only way a Black reformat could cause a bug is if you have code doing something really unusual and unadvisable, like reading Python files from disk and manually parsing them with a regex, or similar. |
blame != history. It's cleaner to have a single point in history reformatting everything, rather than a sprawling number of diffs that make semantic changes and move tokens around to improve style. The easiest way to ignore a sweeping commit with git is Compare that with looking at the blame of a file that's riddled with commits that change formatting around a semantic change, too. They will necessarily touch unrelated lines immediately around the semantic change, poisoning the visible history without a single revision that you can step over.
As Carl says, it's not. I reformatted tens of millions of lines of code with it by now. I could only confidently do this because of the sanity checks that Black performs. |
Will not fix it is then 👍 |
fyi, i wrote https://github.com/wbolster/black-macchiato |
Feature request: for projects not fully adopting black yet, would be nice if we could have some way of using black on the diffs only. I understand this is a non-trivial task. But should be possible to somehow get the diff against
HEAD
and keep only lines from that. Taking over the world one commit at a time?The text was updated successfully, but these errors were encountered: