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

Style/IndentationWidth might be conflicting with start_of_line Lint/EndAlignment style #4105

Closed
brandonweiss opened this issue Mar 10, 2017 · 3 comments · Fixed by #5472
Closed

Comments

@brandonweiss
Copy link
Contributor

I have:

Lint/EndAlignment:
  EnforcedStyleAlignWith: "start_of_line"

And if I turn on Style/IndentationWidth I get weird suggestions, like this:

def carry_attribution_data_from_previous_customer_invoice
  items = if line_items.retrospective.pre_subtotal.any?
            line_items.retrospective.pre_subtotal
  else
    line_items.bill_ahead.pre_subtotal
  end
end

It's obviously trying to indent two lines relative to the if statement, but that's not what I'd want/expect. What I'd expect is:

def carry_attribution_data_from_previous_customer_invoice
  items = if line_items.retrospective.pre_subtotal.any?
    line_items.retrospective.pre_subtotal
  else
    line_items.bill_ahead.pre_subtotal
  end
end
@stakach
Copy link

stakach commented May 3, 2017

I have the same issue:

Lint/EndAlignment:
  EnforcedStyleAlignWith: start_of_line

and

msg << if queued.empty?
  'send queue is empty'
else
  "send queue contains: \n#{queued.join("\n")}"
end

outputs

Use 2 (not -7) spaces for indentation.
        'send queue is empty'
        ^^^
Align else with if.
        else
        ^^^^

If I disable Style/ElseAlignment then I only get the Use 2 (not -7) spaces for indentation.
So I also have to disable Style/IndentationWidth which is undesirable

stakach pushed a commit to acaprojects/ruby-engine that referenced this issue May 3, 2017
@brandonweiss brandonweiss changed the title Style/IndentationWidth might be confliction with start_of_line Lint/EndAlignment style Style/IndentationWidth might be conflicting with start_of_line Lint/EndAlignment style Jun 2, 2017
@brandonweiss
Copy link
Contributor Author

brandonweiss commented Aug 8, 2017

@bbatsov Hey! I've started a PR where I refactored the tests such that they also run Lint/EndAlignment configured with start_of_line in order to create a set of failing tests. I spent several hours today stepping through the on_if block of the cop, introspecting the various nodes and trying to figure out where the bug is, but I don't think I really got anywhere.

My very rudimentary understanding seems to be that when it gets to here, the base_loc#column is wrong. But base_loc is passed through into the on_if hook (via base_node). So… maybe the problem is occurring higher up somewhere? If you could help me by taking a look yourself and/or pointing me in the right direction that would be awesome. Thanks!

@jonas054
Copy link
Collaborator

@brandonweiss I think the problem is that in IndentationWidth#check_assignment, we're looking at the Lint/EndAlignment: EnforcedStyleAlignWith configuration when calculating base, but there's only support for the variable alignment style. The start_of_line style is treated the same as keyword, which is a bug.

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

Successfully merging a pull request may close this issue.

3 participants