ruff icon indicating copy to clipboard operation
ruff copied to clipboard

Option to vertically format arguments if wrapped.

Open funkybob opened this issue 1 year ago • 1 comments

Would it be possible to add a formatter option so that once it decides to split arguments to a call onto a new line, each argument goes on its own line?

So, for example, when it chooses to reformat:

foo = bar(long_name=value, another_argument=1, something_else="12314")

into:

foo = bar(
    long_name=value, another_argument=1, something_else="12314"
)

it will instead produce:

foo = bar(
    long_name=value,
    another_argument=1,
    something_else="12314"
)

(and ideally also add the trailing comma, but that's a separate formatting option, I assume)

I know I can force this formatting to be retained by using the magic trailing comma, but I'd like to not have to think about this.

funkybob avatar Feb 15 '24 01:02 funkybob

Hy @funkybob

The main request in this issue is to have an option to disable the style where ruff tries to format all arguments on a single line before splitting each argument on a separate line. Ruff should already add the trailing comma as you want it to: It adds the trailing comma when each argument is on its own line, but it omits it when formatting all arguments on a single line (the style that you don't want to have).

We're still considering our position on how configurable our formatter should be. There are arguments for an opinionated formatter with very few options. But supporting many options also has its benefits. For now, our position is to avoid formatting style-related options, which includes the option you're asking for.

MichaReiser avatar Feb 15 '24 09:02 MichaReiser