Subject: Re: bug#60321: 29.0.60; ruby-mode indentation of hash or array as first arg in multiline method call

From: Aaron Jensen <[email-masked]>
Date: Sun, 25 Dec 2022 18:46:07 -0500

On Sun, Dec 25, 2022 at 4:30 PM Dmitry Gutov <[email-masked]> wrote:
>
> X-Debbugs-CC: [email-masked]
>
> Splitting off from debbugs#60186, second try.
>
> Since this setting also seems orthogonal to the "simplified" preference,
> and it'll require some more work.
>
> For future reference, here are the relevant Rubocop settings:
>
> https://docs.rubocop.org/rubocop/cops_layout.html#layoutfirsthashelementindentation
> https://docs.rubocop.org/rubocop/cops_layout.html#layoutfirstarrayelementindentation
>
> On 25/12/2022 02:12, Aaron Jensen wrote:
> >> We could also discuss cases like
> >>
> >>     foo = bar({
> >>                 tee: 1,
> >>                 qux: 2
> >>              })
> >>
> >>     baz([
> >>           1,
> >>           2,
> >>           3
> >>         ])
> >>
> >> but those would be an orthogonal feature. And I don't see them much in
> >> the wild, for some reason.
> > The same logic would apply. It doesn't matter how many indent starters
> > there are in a line, the indentation should only increase by one:
> >
> >
> > foo = bar({
> >    tee: 1,
> >    qux: 2
> > })
> >
> > baz([
> >    1,
> >    2,
> >    3
> > ])
> >
> > Of course, that begs the question what happens if you do this:
> >
> > baz([
> >    1,
> >    2,
> >    3
> > ]
> > )
>
> Here are a couple trickier examples:
>
> takes_multi_pairs_hash(x: {
>    a: 1,
>    b: 2
> })

enh-ruby-mode and vim do the same thing, which I think is fine:

takes_multi_pairs_hash(x: {
  a: 1,
  b: 2
})

Though again, the best answer imo is "don't do this".

> and_in_a_method_call({
>    no: :difference
> },
> foo,
> bar)

enh-ruby-mode:

and_in_a_method_call({
  no: :difference
},
                     foo,
                     bar)

Vim:

and_in_a_method_call({
  no: :difference
},
foo,
bar)

I think this falls under something I wouldn't put too much effort into
fixing. I would write it like this:

and_in_a_method_call(
  {
    no: :difference
  },
  foo,
  bar
)

Which indents in a straightforward manner.

If I had to type it as above, I would probably indent it like this:

and_in_a_method_call({
    no: :difference
  },
  foo,
  bar)

But I can't imagine that would be easy to implement at all, so I
wouldn't bother.

> AFAICT even Rubocop doesn't have a setting which would indent the second
> one somewhat reasonably, while keeping two-space indent before "no".
>
> > And, I think again, the answer is a social one, rather than a technical one.
> >
> > enh-ruby-mode and vim both do this this:
> >
> > baz([
> >    1,
> >    2,
> >    3
> > ]
> >     )
>
> Yup, that looks pretty bizarre. OTOH, I don't see why a developer would
> put a newline between "]" and ")" in this case.

Exactly, that's what I meant by a social problem. We have a (somewhat
harsh) saying for stuff like this: you get what you deserve. That's
actually why I don't mind enh-ruby-mode's behavior here. It's clearly
undefined/out of bounds, so that tells a person they are currently out
of bounds and they should get back in bounds.

Aaron