Open MichaReiser opened 11 months ago
My first reaction is that this is similar to Prettier's/Rome's JSX formatting and that we need to use BestFitting
with three variants:
fill
see prototype to fit as many words as possible on the line. The main concern with this is performance:
BestFitting
for the expression BestFit
layout. Using BestFitting for strings would result in a nested BestFitting layout with exponential complexity. Can we remove the need to use
BestFit` for Strings altogether? Black no longer wraps implicitly concatenated strings used as func args in parens, due to this comment. There is an open issue to re-enable it: https://github.com/psf/black/issues/3955
fyi in case anyone was confused and thought this feature was removed in black version 24.1 like i did, the string processing now has to be enabled with --enable-unstable-feature=string_processing
in addition to the --preview
flag.
Black considers to not move forward with the string_processing
preview style (issue)
A simpler aspect of this larger problem is joining strings that get put onto the same line. It constantly annoys me and would love to see it resolved:
# Before
(
""
""
)
# After
("" "")
# Desired
("")
# OR
""
@KotlinIsland we agree. A solution for this is described in https://github.com/astral-sh/ruff/issues/9457
Add support for Black's improved string processing.
Examples
Observations:
+
operatorThe strings must be parenthesized in some contexts, see https://github.com/psf/black/pull/3162/files