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

Add OptionalBooleanParameter AllowedMethods configuration #8489

Closed
bkuhlmann opened this issue Aug 8, 2020 · 4 comments · Fixed by #8790
Closed

Add OptionalBooleanParameter AllowedMethods configuration #8489

bkuhlmann opened this issue Aug 8, 2020 · 4 comments · Fixed by #8790
Labels
enhancement good first issue Easy task, suitable for newcomers to the project help wanted

Comments

@bkuhlmann
Copy link

bkuhlmann commented Aug 8, 2020

Describe the solution you'd like

When using Style/OptionalBooleanParameter, it would be nice to define a set of allowed methods as used via Style/NestedParenthesizedCalls, for example. For instance, when metaprograming, it's common to want to use Object#respond_to_missing?:

def respond_to_missing? name, include_private = false
  # Implementation details...
end

The use of include_private = false, in this case, is what causes this cop to flag the code as a violation. I agree, it is. ...but this is a standard library method which is out of my control as an implementer.

Describe alternatives you've considered

I've been able temporarily work around this issue by using an exclude:

Style/OptionalBooleanParameter:
  Exclude:
    - "path/to/implementation"

This is not ideal as I'd rather not exclude the entire file but ignore a bad practice within the standard library that is out of my control instead.

@marcandre marcandre added enhancement good first issue Easy task, suitable for newcomers to the project help wanted labels Aug 10, 2020
@marcandre
Copy link
Contributor

Good point.
We should definitely exclude respond_to_missing? by default. Can you think of any other builtin callback like that?
Adding the ability to exclude more methods would be a bonus (could be a separate PR)

@bkuhlmann
Copy link
Author

@marcandre Can you think of any other builtin callback like that?

Hmm, I don't know. Object#respond_to_missing? is what I see most often. I know there are others but when searching through my various code bases I came up empty for additional use cases. If I can find more, I'll post back here.

@natematykiewicz
Copy link

Can we start by fixing this for respond_to_missing?, and then fix it for more if more come up?

@bkuhlmann
Copy link
Author

🙇 @natematykiewicz Yeah, I'd like that too. I've still not found another more pressing example other than #respond_to_missing? for the time being. This would be a good start, though!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement good first issue Easy task, suitable for newcomers to the project help wanted
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants