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

Naming/UncommunicativeMethodParamName doesn't take into account underscore prefix #6761

Closed
thomthom opened this issue Feb 11, 2019 · 3 comments

Comments

@thomthom
Copy link
Contributor

I use Ruby in the domain of 3D modelling. So common short variables include x, y, z and u, v. These are flagged by the default rules of Naming/UncommunicativeMethodParamName so I add them to the list of allowed names:

Naming/UncommunicativeMethodParamName:
  AllowedNames:
    - x
    - y
    - z
    - u
    - v
    - uv

However, some times these names are also used as argument names in callbacks of the API. And you don't always use all the arguments being passed in the callback. For instance:

 def onLButtonDoubleClick(_flags, _x, _y, _view)
  # ...
end

However this then will again flag the x and y arguments:

src/tt_truebend/tools/truebend.rb:195:42: C: Naming/UncommunicativeMethodParamName: Method parameter must be at least 3 characters long.
    def onLButtonDoubleClick(_flags, _x, _y, _view)

I could add _x and _y to the list of allowed names. But this still feels like a bug - where the cop should take into account the convention of using underscore prefix to denote unused arguments.


Expected behavior

I would expect Naming/UncommunicativeMethodParamName to take into account the _ prefix convention and strip it away when it checks against the list of allowed short names.

Actual behavior

Currently _x is flagged even if x is an allowed variable name.

Steps to reproduce the problem

Naming/UncommunicativeMethodParamName:
  AllowedNames:
    - x
    - y
    - z
 def onLButtonDoubleClick(_flags, _x, _y, _view)
  # ...
end

RuboCop version

$ [bundle exec] rubocop -V
0.63.1 (using Parser 2.6.0.0, running on ruby 2.2.6 x64-mingw32)
@Drenmi
Copy link
Collaborator

Drenmi commented Feb 12, 2019

I think this sounds like a perfectly reasonable enhancement to the cop. 🙂 Interested in making a PR @thomthom?

@thomthom
Copy link
Contributor Author

Yea, I can make a PR when I have a spare moment.

@thomthom
Copy link
Contributor Author

thomthom commented Apr 1, 2019

Starting work on this now.

thomthom added a commit to thomthom/rubocop that referenced this issue Apr 2, 2019
@bbatsov bbatsov closed this as completed in 4bc7d8c Apr 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants