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

Layout/BeginEndAlignment not always correctly detecting alignment #8710

Closed
tas50 opened this issue Sep 13, 2020 · 0 comments · Fixed by #8719
Closed

Layout/BeginEndAlignment not always correctly detecting alignment #8710

tas50 opened this issue Sep 13, 2020 · 0 comments · Fixed by #8719
Labels

Comments

@tas50
Copy link
Contributor

tas50 commented Sep 13, 2020

Expected behavior

Layout/BeginEndAlignment should correctly detect begin/end alignment.

Actual behavior

If begin/end is assigned to value then the alignment is being incorreclty detected:

Steps to reproduce the problem

Given this code:

class RspecVersionString
  def self.rspec_version_string
    @rspec_version_string ||= begin
                                stubs = Gem::Specification.send(:installed_stubs, Gem::Specification.dirs, "rspec-core-*.gemspec")
                                stubs.select! { |stub| stub.name == "rspec-core" && Gem::Dependency.new("rspec-core", ">= 0").requirement.satisfied_by?(stub.version) }
                                stubs.max_by(&:version).version.to_s
                              end
  end
end
/Users/tsmith/test.rb:7:31: W: [Corrected] Layout/BeginEndAlignment: end at 7, 30 is not aligned with @rspec_version_string ||= begin at 3, 4.
                              end
                              ^^^

1 file inspected, 1 offense detected, 1 offense corrected

Autocorrects to this:

class RspecVersionString
  def self.rspec_version_string
    @rspec_version_string ||= begin
                                stubs = Gem::Specification.send(:installed_stubs, Gem::Specification.dirs, "rspec-core-*.gemspec")
                                stubs.select! { |stub| stub.name == "rspec-core" && Gem::Dependency.new("rspec-core", ">= 0").requirement.satisfied_by?(stub.version) }
                                stubs.max_by(&:version).version.to_s
    end
  end
end

RuboCop version

master

@koic koic added the bug label Sep 15, 2020
koic added a commit to koic/rubocop that referenced this issue Sep 15, 2020
…ment`

Fixes rubocop#8710 and rubocop#8717.

This PR fixes a false positive for `Layout/RescueEnsureAlignment`
when `Layout/BeginEndAlignment` cop is not enabled status (e.g. pending, disabled).

This patch includes workaround for pending status until RuboCop 1.0 is released.
koic added a commit that referenced this issue Sep 15, 2020
…re_alignment

[Fix #8710] Fix a false positive for `Layout/RescueEnsureAlignment`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants