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

Open
bkuhlmann opened this issue Aug 8, 2020 · 2 comments
Open

Add OptionalBooleanParameter AllowedMethods configuration #8489

bkuhlmann opened this issue Aug 8, 2020 · 2 comments

Comments

@bkuhlmann
Copy link

@bkuhlmann 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
Copy link
Contributor

@marcandre marcandre commented Aug 10, 2020

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

@bkuhlmann bkuhlmann commented Aug 10, 2020

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.