asottile/add-trailing-comma

Don't add commas to single argument to function

PeterJCLaw opened this issue · 1 comments

If I have a single argument to a function, I would like add-trailing-comma to not try to add a trailing comma to that argument when doing so means rewriting the overall indentation.

For example:

# this is left alone
the_list.append(Thing(x, y, z))

# but this is changed
the_list.append(Thing(
    x,
    y,
    z,
))

# into this
the_list.append(
    Thing(
        x,
        y,
        z,
    ),
)

I realise that it's a bit of an odd case, however I've found that the vertical style works really well as part of a style guide which aims to minimise diffs. (I use flake8-commas, which is already aware of this case and doesn't error about it)

I was a little surprised that add-trailing-comma changes this case as I consider it the same as the first case (all on one line).

Would it be possible to add an option to ignore cases where there is a single argument and it is formatted in this manner?

For clarity: if the code is already in the third form, but just missing the trailing comma, I think it would still be useful to add one there.

this was an intentional change to fix #42

note that if it's just brackets a-t-c does as you suggest

there are no options and I do not want to add one for this case (it's also afaict impossible to discern from the cases in #42 )