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

Rails/Delagate gets confused by private class methods #712

Closed
Darhazer opened this issue Jun 8, 2022 · 0 comments · Fixed by #736
Closed

Rails/Delagate gets confused by private class methods #712

Darhazer opened this issue Jun 8, 2022 · 0 comments · Fixed by #736
Labels
bug Something isn't working

Comments

@Darhazer
Copy link
Member

Darhazer commented Jun 8, 2022

Given the code:

class A
  class << self
    private

    def foo
    end
  end

  def bar
    baz.bar
  end
end

Rails/Delegate doesn't produce an offence for def bar. Removing the private on line 3 however correctly triggers the cop. Note that the bar method itself is not private.


Expected behavior

An offence for the delegation. Inner classes' private declarations should be ignored when checking whether this is a private delegation. Note that this also would be ignored while it should not:

class A
  class B
    private

    def foo
    end
  end

  def bar
    baz.bar
  end
end

Actual behavior

no offences detected

Steps to reproduce the problem

This is extremely important! Providing us with a reliable way to reproduce
a problem will expedite its solution.

RuboCop version

Include the output of rubocop -V or bundle exec rubocop -V if using Bundler. Here's an example:
You can see extension cop versions (e.g. rubocop-rails, rubocop-performance, and others) output by rubocop -V,
include them as well. Here's an example:

$ [bundle exec] rubocop -V
rubocop -V
1.30.1 (using Parser 3.1.2.0, rubocop-ast 1.18.0, running on ruby 3.1.2 arm64-darwin21)
  - rubocop-performance 1.14.1
  - rubocop-rails 2.14.2
  - rubocop-rake 0.6.0
  - rubocop-rspec 2.11.1
@Darhazer Darhazer added the bug Something isn't working label Jun 28, 2022
Darhazer added a commit that referenced this issue Jun 29, 2022
Darhazer added a commit that referenced this issue Jun 29, 2022
Darhazer added a commit that referenced this issue Jun 29, 2022
@koic koic closed this as completed in #736 Jul 5, 2022
koic added a commit that referenced this issue Jul 5, 2022
…gate

[Fix #712] Fixed false negative when visibility modifier is declared in nested class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
1 participant