Formatter: Allow configurable soft-indent width (vs. hard/block indent) #10191
Replies: 2 comments 4 replies
-
So if I understand well, this : class Ssl(
rawsock,
protocol,
):
def _make_ssl_transport(
rawsock,
protocol,
):
def _make_ssl_transport(
rawsock,
protocol,
):
if plop(
rawsock,
protocol,
):
... Will become, with soft-indent-multiple = 2 : class Ssl(
rawsock,
protocol,
):
def _make_ssl_transport(
rawsock,
protocol,
):
def _make_ssl_transport(
rawsock,
protocol,
):
if plop(
rawsock,
protocol,
):
... Or is it only for private functions ? class Ssl(
rawsock,
protocol,
):
def _make_ssl_transport(
rawsock,
protocol,
):
def _make_ssl_transport(
rawsock,
protocol,
):
if plop(
rawsock,
protocol,
):
... But the the option naming seems ambiguous (soft-indent-multiple). It is like full indent will be multiply, this way : class Ssl(
rawsock,
protocol,
):
def _make_ssl_transport(
rawsock,
protocol,
):
def _make_ssl_transport(
rawsock,
protocol,
):
... PS : To distinguish better functions parameters, did you try to change your highlight colours for functions definitions ? 🙄 You can use pygments or for more config you can use Tree Sitter by example for nvim. With tree sitter you can, by example, put a brighter colour for functions parameters. |
Beta Was this translation helpful? Give feedback.
-
I don't think that we would add such an option today. We consider adding more option in the future but our primary aim for now is black compatibility. There's a similar request that we track in #8360, except that it requests to add more indentation rather than less. There's also a technical question where it's unclear to me how this style would be implemented when using |
Beta Was this translation helpful? Give feedback.
-
Consider the indentation of the following example function, taken from the documentation, as produced by
ruff format
:The formatter uses a "soft indent" of 4 spaces to allow the parameter list to span multiple lines, which also aligns with the "block indent" used for the function body. The
if
statements introduce a further block indent to increase the indent level.In my opinion, the "soft indent," which may be optionally used to wrap within parentheses and brackets, should be easily visually distinguishable from the mandatory hard indent, which affects control flow.
Would the
ruff
maintainers be interested in merging a PR that would introduce a new option (something along the lines ofsoft-indent-multiple
) that would allow the user to specify an alternate indentation width for soft indents?For example, setting the
soft-indent-multiple = 2
would produce the following output:Obviously a personal preference, but I think it's valuable to see a clear visual difference between the parameters list and the function body itself. It makes it easier for me to skip past the parameters (there are a lot for this function!) and get to the code itself. In the default-formatted output, the only visual break is from the closing paren and colon.
If this is something that could be merged, I'm happy to open a pull request with all necessary code and tests to add this as a configurable option.
Beta Was this translation helpful? Give feedback.
All reactions