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

False positive with Style/MissingRespondToMissing when using inline access modifiers #8330

Closed
voikya opened this issue Jul 13, 2020 · 0 comments · Fixed by #8421
Closed

False positive with Style/MissingRespondToMissing when using inline access modifiers #8330

voikya opened this issue Jul 13, 2020 · 0 comments · Fixed by #8421
Labels

Comments

@voikya
Copy link

voikya commented Jul 13, 2020

When using inline access modifiers (like private def respond_to_missing?(...)), the Style/MissingRespondToMissing is inappropriately returning a false positive, stating there is no respond_to_missing? method defined.

Both of these methods are initially defined as private:

BasicObject.private_method_defined?(:method_missing)
 => true

Kernel.private_method_defined?(:respond_to_missing?)
 => true

Expected behavior

The Style/MissingRespondToMissing should not report an issue if respond_to_missing? is defined using an inline private modifier.

Actual behavior

Rubocop validation fails.

Steps to reproduce the problem

Rubocop configuration:

Style/AccessModifierDeclarations:
  EnforcedStyle: inline

Style/MissingRespondToMissing:
  Enabled: true

Test file:

class Test
  private def method_missing(method, *args, &block)
    super
  end

  private def respond_to_missing?(method, include_private = false)
    super
  end
end

Result:

test.rb:2:11: C: Style/MissingRespondToMissing: When using method_missing, define respond_to_missing?.
  private def method_missing(method_id, *args, &block) ...

In contrast, no issue is reported with this file, using group-style access modifiers:

class Test
  private
  def method_missing(method_id, *args, &block)
    super
  end

  def respond_to_missing?(method, include_private = false)
    super
  end
end

RuboCop version

$ rubocop -V
0.88.0 (using Parser 2.7.1.4, rubocop-ast 0.1.0, running on ruby 2.6.6 x86_64-darwin19)
@marcandre marcandre added the bug label Jul 13, 2020
koic added a commit to koic/rubocop that referenced this issue Jul 31, 2020
…ssing`

Fixes rubocop#8330.

This PR fixes a false positive for `Style/MissingRespondToMissing`
when defined method with inline access modifier.
bbatsov pushed a commit that referenced this issue Jul 31, 2020
Fixes #8330.

This PR fixes a false positive for `Style/MissingRespondToMissing`
when defined method with inline access modifier.
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