psf / black

The uncompromising Python code formatter

Home Page:https://black.readthedocs.io/en/stable/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ENH: incremental changes to modify only code neighboring already changed lines

mattip opened this issue · comments

Idea: allow running black with a -n --dry-run=filename option and store the resulting changeset. Then allow using this in a subsequent run to only update newly found changes.

Rational: In a workflow on an established managed repository, this would allow running black incrementally, reformatting only parts of the code that have been changed, minimizing git churn and blame lines.

This is something we explicitly don't support. Incremental style changes are against PEP 8's philosophy of staying consistent within a file. They also mix formatting changes with semantic changes, making review harder than it needs to be. See #134 for a longer explanation.

Reformat your entire project in one go. Then there is a single commit that is trivial to omit using git hyper-blame or simply by using git blame $BLACK_COMMIT^ -- $FILE. It's a cleaner approach than trying to smear adoption over time.

See also: #320

Also FYI, I wrote darker for applying Black formatting only to lines which have changed in the Git working tree since the last commit.