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

Lint/UselessMethodDefinition: false positive(?) with mixed in method #8678

Open
leoarnold opened this issue Sep 9, 2020 · 1 comment
Open

Comments

@leoarnold
Copy link
Contributor

Expected behavior

Given the test script

require 'action_controller'

class A
  include ActiveSupport::Configurable
  include ActionController::RequestForgeryProtection

  def valid_authenticity_token?(session, encoded_masked_token)
    super
  end
end

class B
  include ActiveSupport::Configurable
  include ActionController::RequestForgeryProtection
end

the method definition in class A seems necessary

$ irb -I. -rtest.rb
2.5.8 :001 > A.new.respond_to?(:valid_authenticity_token?)
 => true 
2.5.8 :002 > B.new.respond_to?(:valid_authenticity_token?)
 => false 

and therefore is not an offense.

Actual behavior

$ rubocop --only Lint/UselessMethodDefinition test.rb 
Inspecting 1 file
W

Offenses:

test.rb:7:3: W: Lint/UselessMethodDefinition: Useless method definition detected.
  def valid_authenticity_token?(session, encoded_masked_token) ...
  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

1 file inspected, 1 offense detected, 1 offense auto-correctable

Steps to reproduce the problem

See above

RuboCop version

$ [bundle exec] rubocop -V
0.90.0 (using Parser 2.7.1.4, rubocop-ast 0.3.0, running on ruby 2.5.8 x86_64-linux)
@marcandre
Copy link
Contributor

You are correct it isn't useless in the sense of having no side-effect, so maybe we should change the wording, but the only thing this code does is make the method public (and slow it down a bit).

It should be replaced by public :valid_authenticity_token?

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

2 participants