Skip to content

Indent relative to block with multiline method chains #12297

@mlwyatt

Description

@mlwyatt

Is your feature request related to a problem? Please describe.

While correct when one thinks indent "relative to statement", the following code reads easier if indented "relative to block start"

# Relative to statement
data = {
  users:
    User
      .where(id: id_list)
      .group_by(&:last_name)
      .transform_values do |v|
      v.map(&:as_json)
    end
}

# Relative to block
data = {
  users:
    User
      .where(id: id_list)
      .group_by(&:last_name)
      .transform_values do |v|
        v.map(&:as_json)
      end
}

Describe the solution you'd like

Unless there's already a config option I can set that I have yet been able to find, either a new cop or a new option for an existing cop to enforce either style would be great

Describe alternatives you've considered

I've searched the issue list for indent and couldn't find anything. In this particular simple example, I can change the do block to use {}, but some block will be too long or multiple statements

data = {
  users:
    User
      .where(id: id_list)
      .group_by(&:last_name)
      .transform_values { |v| v.map(&:as_json) }
}

Any help would be greatly appreciated

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions