Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enforce strict 2 space indentation for multiline method invocation as well as multiline hash definitions #1744

Closed
idlecool opened this Issue Mar 27, 2015 · 7 comments

Comments

Projects
None yet
6 participants
@idlecool
Copy link

commented Mar 27, 2015

This is a question and not an issue. I am posting it here as I don't know where else to ask. I have already checked existing issues based on keyword search but couldn't seem to find any issue related to this.

Is it possible to enforce a consistent 2 space indentation for multiline method calls and multiline hash definition?

I have created a sample code to explain my concern.

class Example
  def hello_world
    ## Hash Definitions
    # strict 2 space indentation, OK
    user_alpha_beta_gamma = {
      name: "John Doe",
      email: "john@example",
      role: :admin
    }

    user_theta = {
      name: "John Doe",
      email: "john@example",
      role: :admin
    }

    # inconsistent indentation! NOT OKAY
    user_alpha_beta_gamma = {
                             name: "John Doe",
                             email: "john@example",
                             role: :admin
                            }

    user_theta = {
                  name: "John Doe",
                  email: "john@example",
                  role: :admin
                 }

    ## Method Calls
    # strict 2 space indentation, OK
    Mailer.deliver(
      to: "bob@example.com",
      from: "john@example.com",
      subject: "hello there",
      body: "this is the first email"
    )

    Mailer.quick_deliver(
      to: "bob@example.com",
      from: "john@example.com",
      subject: "hello there",
      body: "this is the second email"
    )

    # inconsistent indentation! NOT OKAY
    Mailer.deliver(to: "bob@example.com",
                   from: "john@example.com",
                   subject: "hello there",
                   body: "this is the first email"
                  )

    Mailer.quick_deliver(to: "bob@example.com",
                         from: "john@example.com",
                         subject: "hello there",
                         body: "this is the second email"
                        )
  end
end

Is there a way I can enforce a strict 2 space indentation scheme?

@jonas054

This comment has been minimized.

Copy link
Collaborator

commented Mar 28, 2015

The NOT OKAY hash examples that you give are already reported as offenses with the default configuration. This is because the first key/value pair is preceded by a line break. If you change it to

    user_alpha_beta_gamma = { name: "John Doe",
                              email: "john@example",
                              role: :admin }

it passes inspection.

For the same reason, all the method call examples pass.

What you're talking about is to require line break before the first parameter or element. This could of course be added, either to existing cops as configuration options, or as new cops.

@alexdowad

This comment has been minimized.

Copy link
Contributor

commented Dec 22, 2015

Maintainers, do you want configuration options added for this style? If yes, I'll add them. If no, then let's close this issue.

@bbatsov

This comment has been minimized.

Copy link
Collaborator

commented Dec 23, 2015

What you're talking about is to require line break before the first parameter or element. This could of course be added, either to existing cops as configuration options, or as new cops.

I think we now have a cop that does this (but it's disabled by default). There isn't any work to be done here.

@bbatsov bbatsov closed this Dec 23, 2015

@sheerun

This comment has been minimized.

Copy link

commented Sep 20, 2016

I haven't found it. Any help?

@jonas054

This comment has been minimized.

@grosser

This comment has been minimized.

Copy link
Contributor

commented Mar 9, 2019

I'm trying to get that enforced but did not find any way ... dug though https://github.com/rubocop-hq/rubocop/blob/master/config/default.yml and nothing seems to work.
@jonas054 the link is dead, do you have a new one ?

@jonas054

This comment has been minimized.

Copy link
Collaborator

commented Mar 10, 2019

Yes, I should not have linked to master since it's a moving target. Here's the link I should have posted originally:
https://github.com/rubocop-hq/rubocop/blob/v0.42.0/config/disabled.yml#L37-L53
And here's a more current one:
https://github.com/rubocop-hq/rubocop/blob/v0.65.0/config/default.yml#L594-L613

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.