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 new `Style/OptionalBooleanParameter` cop #8412

Merged
merged 1 commit into from Jul 30, 2020

Conversation

@fatkodima
Copy link
Contributor

@fatkodima fatkodima commented Jul 29, 2020

https://rubystyle.guide/#boolean-keyword-arguments

# bad
def some_method(bar = false)
  puts bar
end

# good
def some_method(bar: false)
  puts bar
end
Style/BooleanKeywordArgument:
Description: 'Use keyword arguments when defining method with boolean argument.'
StyleGuide: '#boolean-keyword-arguments'
Enabled: pending

This comment has been minimized.

@koic

koic Jul 29, 2020
Member

I think that this cop is unsafe, just like Style/OptionalArguments cop.

This comment has been minimized.

@marcandre

marcandre Jul 29, 2020
Contributor

I'm curious why Style/OptionalArguments is "unsafe", or this one?

For this one, my only concern is if there is a call to super, or super(that_argument), then maybe there should be no offense since this method is just copying the interface it inherits. Maybe there should not be an offense then; the base method will be flagged probably. What other cases are unsafe?

This comment has been minimized.

@koic

koic Jul 29, 2020
Member

I think it means a breaking change to users if the API signature is a published interface.
https://martinfowler.com/bliki/PublishedInterface.html

This comment has been minimized.

@fatkodima

fatkodima Jul 29, 2020
Author Contributor

Made it unsafe.

Copy link
Contributor

@marcandre marcandre left a comment

I love it when a new cop improves our codebase!

Here, I think all of these true/false were clear examples of arguments that can not be understood when called.

lib/rubocop/cop/registry.rb Outdated Show resolved Hide resolved
lib/rubocop/cop/style/boolean_keyword_argument.rb Outdated Show resolved Hide resolved
@fatkodima fatkodima force-pushed the fatkodima:boolean_keyword_argument-cop branch from 12b12f2 to 786d100 Jul 29, 2020
@bbatsov
Copy link
Collaborator

@bbatsov bbatsov commented Jul 30, 2020

Seems we've made a mistake with the heading in the style guide - I think the cop should be named OptionalBooleanParameter.

@fatkodima fatkodima force-pushed the fatkodima:boolean_keyword_argument-cop branch from 786d100 to cd8d521 Jul 30, 2020
@fatkodima fatkodima changed the title Add new `Style/BooleanKeywordArgument` cop Add new `Style/OptionalBooleanParameter` cop Jul 30, 2020
@fatkodima fatkodima force-pushed the fatkodima:boolean_keyword_argument-cop branch from cd8d521 to 45250d2 Jul 30, 2020
@fatkodima
Copy link
Contributor Author

@fatkodima fatkodima commented Jul 30, 2020

Updated with new name.

@bbatsov bbatsov merged commit df70484 into rubocop-hq:master Jul 30, 2020
26 checks passed
26 checks passed
windows 2.4
Details
windows 2.5
Details
windows 2.6
Details
windows 2.7
Details
windows mingw
Details
ci/circleci: cc-setup Your tests passed on CircleCI!
Details
ci/circleci: cc-upload-coverage Your tests passed on CircleCI!
Details
ci/circleci: documentation-checks Your tests passed on CircleCI!
Details
ci/circleci: jruby-9.2-ascii_spec Your tests passed on CircleCI!
Details
ci/circleci: jruby-9.2-rubocop Your tests passed on CircleCI!
Details
ci/circleci: jruby-9.2-spec Your tests passed on CircleCI!
Details
ci/circleci: ruby-2.4-ascii_spec Your tests passed on CircleCI!
Details
ci/circleci: ruby-2.4-rubocop Your tests passed on CircleCI!
Details
ci/circleci: ruby-2.4-spec Your tests passed on CircleCI!
Details
ci/circleci: ruby-2.5-ascii_spec Your tests passed on CircleCI!
Details
ci/circleci: ruby-2.5-rubocop Your tests passed on CircleCI!
Details
ci/circleci: ruby-2.5-spec Your tests passed on CircleCI!
Details
ci/circleci: ruby-2.6-ascii_spec Your tests passed on CircleCI!
Details
ci/circleci: ruby-2.6-rubocop Your tests passed on CircleCI!
Details
ci/circleci: ruby-2.6-spec Your tests passed on CircleCI!
Details
ci/circleci: ruby-2.7-ascii_spec Your tests passed on CircleCI!
Details
ci/circleci: ruby-2.7-rubocop Your tests passed on CircleCI!
Details
ci/circleci: ruby-2.7-spec Your tests passed on CircleCI!
Details
ci/circleci: ruby-head-ascii_spec Your tests passed on CircleCI!
Details
ci/circleci: ruby-head-rubocop Your tests passed on CircleCI!
Details
ci/circleci: ruby-head-spec Your tests passed on CircleCI!
Details
@bbatsov
Copy link
Collaborator

@bbatsov bbatsov commented Jul 30, 2020

Great cop!

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

Successfully merging this pull request may close these issues.

None yet

4 participants
You can’t perform that action at this time.