rubocop / rubocop

A Ruby static code analyzer and formatter, based on the community Ruby style guide.

Home Page:https://docs.rubocop.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Automated `Lint/UnusedMethodArgument` fix updates API signature, but does not update consumers

david-alvarez-rosa opened this issue · comments

Whenever the automated fixes for Lint/UnusedMethodArgument check are executed, it prefixes all unused parameters from method signature with an underscore _.

However, it does not update the consumers of the API, which can break the code at runtime.

Example

def my_method(unused_var)
  puts "Hello!"
end

def other_method
  my_method(unused_var: "whatever")
end

Will be changed to

def my_method(_unused_var)
  puts "Hello!"
end

def other_method
  my_method(unused_var: "whatever")
end

however, the caller of the method is not changed, which breaks the code.


Expected behavior

Expected behavior would be to change callers

def my_method(_unused_var)
  puts "Hello!"
end

def other_method
  my_method(_unused_var: "whatever")
end

or at least notify the user.

Just to clear, the requested change is the following:

- my_method(unused_var: "whatever")
+ my_method(_unused_var: "whatever")

Actual behavior

The actual behavior of RuboCop does not change callers.

Steps to reproduce the problem

As explained above.

RuboCop version

$ rubocop -V        
Ignoring jaro_winkler-1.5.4 because its extensions are not built. Try: gem pristine jaro_winkler --version 1.5.4
Ignoring json-2.6.2 because its extensions are not built. Try: gem pristine json --version 2.6.2
1.36.0 (using Parser 3.1.2.1, rubocop-ast 1.21.0, running on ruby 2.6.10) [universal.x86_64-darwin22]

My bad, seems that this was not an automated change done by RuboCop.