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

Strange indentation error with if/else alignment #1691

Closed
zmoazeni opened this issue Mar 5, 2015 · 6 comments
Closed

Strange indentation error with if/else alignment #1691

zmoazeni opened this issue Mar 5, 2015 · 6 comments
Assignees

Comments

@zmoazeni
Copy link

zmoazeni commented Mar 5, 2015

Ruby code:

bar = true

some_var = if bar
  "it's true!"
else
  "it's not true"
end

puts some_var

rubocop config:

Style/ElseAlignment:
  Enabled: false

Lint/EndAlignment:
  Enabled: false

Error message:

foo.rb:4:3: C: Use 2 (not -9) spaces for indentation.
  "it's true!"
  ^^^^^^^^^

If I don't want to enforce if/else formats, how can I disable this without getting a warning?

@bquorning
Copy link
Contributor

Yeah, that’s a bit weird. The warning comes from the Style/IndentationWidth cop, but it actually looks at the Lint/EndAlignment configuration in this case.

To fix it, you would either disable Style/IndentationWidth, or enable Lint/EndAlignment with the configuration

Lint/EndAlignment:
  AlignWith: variable

@zmoazeni
Copy link
Author

zmoazeni commented Mar 5, 2015

To fix it, you would either disable Style/IndentationWidth

Wouldn't this disable indentation checking across the board? Ignoring stuff like:

def foo
    1 # 4 spaces
end

or enable Lint/EndAlignment with the configuration

Like I said, we don't want to enforce if/else alignment rules. If we choose variable then it doesn't allow:

some_var =
  if bar
    "it's true!"
  else
    "it's not true"
  end

@jonas054
Copy link
Collaborator

I think the variable style of Lint/EndAlignment should be changed so that it accepts (enforces) alignment with the if keyword in the above example where there is a line break after =.

@bbatsov
Copy link
Collaborator

bbatsov commented Apr 5, 2015

I think the variable style of Lint/EndAlignment should be changed so that it accepts (enforces) alignment with the if keyword in the above example where there is a line break after =.

Definitely.

@jonas054 jonas054 self-assigned this Apr 5, 2015
bbatsov added a commit that referenced this issue Apr 8, 2015
[Fix #1691] Handle var = <line break> in EndAlignment
crimsonknave pushed a commit to crimsonknave/rubocop that referenced this issue Apr 13, 2015
In this case, the cop should enforce keyword alignment
even if variable alignment is selected in configuration.
@patbl
Copy link

patbl commented Mar 12, 2018

So is it not possible to allow both

some_var = if bar
             "it's true!"
           else
             "it's not true"
           end

and

some_var = if bar
  "it's true!"
else
  "it's not true"
end

with Layout/IndentationWidth enabled?

@jonas054
Copy link
Collaborator

No. Allowing two styles is generally not something we like to do in RuboCop. It's either/or.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants