Black does a lot of things right, but imo it
must not change the indentation of comments. Unless this is fixed, I shall not blacken Leo's code base.
I used two kinds of comments throughout Leo: leading comments and trailing comments. Leading comments apply to the following line or lines:
# Compute g.app.signon.
signon = ['Leo %s' % leoVer]
...
Trailing comments apply only to the immediately preceding line:
self.batchMode = False
# True: run in batch mode.
self.debug = []
# A list of switches to be enabled.
self.diff = False
# True: run Leo in diff mode.
Imo, dedenting these comments is simply wrong.
Next steps
I'll raise this issue with the black devs, after doing my homework, which will be to suggest a patch. The last time I looked, handling whitespace in comments and strings was difficult.
If necessary, I'll copy a patched (forked) version of black to leo/external and use that for Leo's black command.
Another possibility: support black-like line breaks in Leo's legacy beautify commands. This is
#1266.
Summary
Black should keep its hands off comments.
Workarounds include a fork of black, or using black-like line breaking in Leo's token-based beautify commands.
Edward