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

autocorrect doesn't fully fix if / elsif block indentation #1348

Closed
strongriley opened this issue Sep 25, 2014 · 3 comments
Closed

autocorrect doesn't fully fix if / elsif block indentation #1348

strongriley opened this issue Sep 25, 2014 · 3 comments
Assignees

Comments

@strongriley
Copy link

original:

    street2 = if result[:secondary_address].present?
      result[:secondary_address]
    elsif result[:address2].present?
      if result[:address2] =~ /^\s*(\d+)\s*$/
        "# #{$1}"
      else
        result[:address2]
      end
    end

autocorrected:

    street2 = if result[:secondary_address].present?
                result[:secondary_address]
    elsif result[:address2].present?
                if result[:address2] =~ /^\s*(\d+)\s*$/
                  "# #{Regexp.last_match[1]}"
                else
                  result[:address2]
                end
    end

What I would expect:

    street2 = if result[:secondary_address].present?
                result[:secondary_address]
              elsif result[:address2].present?
                if result[:address2] =~ /^\s*(\d+)\s*$/
                  "# #{Regexp.last_match[1]}"
                else
                  result[:address2]
                end
              end

Version:

rubocop -V
0.26.0 (using Parser 2.2.0.pre.4, running on ruby 1.9.3 x86_64-darwin13.3.0)
@bbatsov
Copy link
Collaborator

bbatsov commented Sep 25, 2014

@jonas054 Would you have a look at this?

@jonas054 jonas054 self-assigned this Sep 25, 2014
@jonas054
Copy link
Collaborator

Yes!

@jonas054
Copy link
Collaborator

I think there's a reason why we haven't added autocorrect to the EndAlignment cop. It's because it's a lint cop, and the reasoning is that the misindented end could actually be meant to close a different structure than it does. Autocorrecting it could mask another error.

The bad elsif indentation is not even detected. That's a different story.

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

3 participants