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/Next autocorrection breaks indentation in some cases #2450

Closed
deivid-rodriguez opened this issue Nov 23, 2015 · 9 comments
Closed

Style/Next autocorrection breaks indentation in some cases #2450

deivid-rodriguez opened this issue Nov 23, 2015 · 9 comments

Comments

@deivid-rodriguez
Copy link
Contributor

The following file

def a
  res = nil

  [1, 2, 3].each do |number|
    if number > 2
      if number == 1
        res = "it's one"
      else
        res = "it's not one"
      end
    end
  end

  res
end

gets autocorrected to

def a
  res = nil

  [1, 2, 3].each do |number|
    next unless number > 2
    if number == 1
      res = "it's one"
    else
      res = "it's not one"
          end
  end

  res
end

introducing a Lint/EndAlignment offense.

@lumeet
Copy link
Contributor

lumeet commented Nov 24, 2015

I think this has been fixed on master with #2429. #2453 wouldn't break it either.

@deivid-rodriguez
Copy link
Contributor Author

With both #2429 and #2453 I still get an incorrect autocorrection

def a
  res = nil

  [1, 2, 3].each do |number|
    next unless number > 2
    res = if number == 1
            "it's one"
          else
            "it's not one"
    end
  end

  res
end

@lumeet
Copy link
Contributor

lumeet commented Nov 24, 2015

Unless I'm completely wrong, Style/Next is not to be blamed for this. Using the default configuration with Next disabled, I'm getting similar alignment for the end.

@jonas054
Copy link
Collaborator

See this comment for an explanation of why the ends don't get corrected. In this case, not correcting end alignment by default is not a good feature, since other cops have misaligned them during auto-correction.

teeparham pushed a commit to rgeo/rgeo that referenced this issue Dec 3, 2015
teeparham pushed a commit to rgeo/rgeo that referenced this issue Dec 3, 2015
@deivid-rodriguez
Copy link
Contributor Author

@jonas054 So what would be the best solution here? Maybe allowing autocorrections which leave offenses in the corrected code (with the expectation that they will be corrected by other cops) is not a good idea?

@jonas054
Copy link
Collaborator

jonas054 commented Dec 4, 2015

That's what we usually do, but ends are special -- they might not be auto-corrected, depending on configuration. So if they were correctly aligned to begin with, it would be much better if Style/Next could make sure that they continued to be correctly aligned.

@deivid-rodriguez
Copy link
Contributor Author

So then we should consider this a bug. Right?

@jonas054
Copy link
Collaborator

jonas054 commented Dec 9, 2015

Yes, I think so.

@alexdowad
Copy link
Contributor

I'm about to push a fix for this one to my open PR.

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

4 participants