2

Currently, ruby-mode in Emacs 27 indents the following snippets like this:

expect(foo).to match(
                 bar
               )

expect(foo).to \
              match(bar)

Is there a way to have them indented like this, to avoid overly long lines?

expect(foo).to match(
  bar
)

expect(foo).to \
  match(bar)

EDIT: I am not sure I understand how this relates to paren-less method calls. The indentation for the following has all the parens present and is indented in the same way.

expect(foo).to(match(
                 bar
               ))

The example with the line continuation (\) on the other hand is unambiguous, correct? "Indent one level further than the previous non-whitespace line" should cover all cases, unless I am missing something.

The first two examples in this question, which are the default in current ruby-mode both get flagged by RuboCop in the default config with Indent the first parameter one step more than the start of the previous line. I suppose this is not a dead-set argument for or against a particular indentation style. But it might be worth considering providing it as an option given RuboCop's popularity.

1 Answers1

1

The problem with both of these is ruby-mode tries to be consistent and apply similar indentation rules to similar syntax constructs.

We try to support the popular indentation approach for paren-less method calls:

class Book < ActiveRecord::Base
   belongs_to :subject
   validates_presence_of :title
   validates_numericality_of :price,
                             message: "Error Message",
                             tee: qux(
                               1, 2,
                               3
                             )
end

As a result, however, the RSpec syntax you gave examples of gets indented using the same rules. Do do it differently, we need some way to distinguish between these cases.

Or, if you're sure that you and your colleagues wouldn't mind to see the above example indented differently as well, we can add a user option to choose between the two indentation approaches.

Either way, please file a bug report with M-x report-emacs-bug with additional info according to the above.

Dmitry
  • 3,508
  • 15
  • 20
  • Thanks for answering so quickly. I have edited my question, with an example of all parens present, which is indented in the same way. – Nickolay Kolev Dec 08 '19 at 20:58
  • That would easier to support, yes (as an optional behavior as well). A bug report would help anyway (that's just how we do Emacs development). – Dmitry Dec 09 '19 at 15:55
  • A user option like the one mentioned would make my rubocop overlord easier to work with -- is there any news on this? – user1070300 Mar 08 '22 at 09:52