astral-sh / ruff

An extremely fast Python linter and code formatter, written in Rust.

Home Page:https://docs.astral.sh/ruff

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Format rule to keep together }, { for list of objects

darowny opened this issue · comments

Is there a setting or a rule that will keep this style of formatting ? I mean keeping }, { together and then hugging }] at the end?

trans = [{
    'first': Stuff,
    'second': Other,
    'third': Blah,
    'fourth': Sth
}, {
    'first': Stuff,
    'second': Other,
    'third': Blah,
    'fourth': Sth
}, {
    'first': Stuff,
    'second': Other,
    'third': Blah,
    'fourth': Sth
}]

I tried 0.3.4 and 0.4.3 ruff for this, with enabled preview, shouldn't it keep hugging braces and brackets ?
Related discussion I think

Hi @darowny

No, there's no such formatter setting.

The hugging preview style only applies if the array (or dict or set) is the only argument in a function call or the only content of a prenthesized expression

trans = call([
    {
        "first": Stuff,
        "second": Other,
        "third": Blah,
        "third": Blah,
    }
])


trans = a + ([
    {
        "first": Stuff,
        "second": Other,
        "third": Blah,
        "third": Blah,
    }
])