Skip to content

Commit

Permalink
[rubocop#8489](rubocop#8489) Exclude method respond_to_missing? from …
Browse files Browse the repository at this point in the history
…OptionalBooleanParameter cop.
  • Loading branch information
em-gazelle committed Sep 16, 2020
1 parent 3282218 commit 2f4a16d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -45,6 +45,7 @@
* [#8500](https://github.com/rubocop-hq/rubocop/issues/8500): Add `in?` to AllowedMethods for `Lint/SafeNavigationChain` cop. ([@tejasbubane][])
* [#8629](https://github.com/rubocop-hq/rubocop/pull/8629): Fix the cache being reusable in CI by using crc32 to calculate file hashes rather than `mtime`, which changes each CI build. ([@dvandersluis][])
* [#8621](https://github.com/rubocop-hq/rubocop/issues/8621): Add helpful Infinite Loop error message. ([@iSarCasm][])
* [#8489](https://github.com/rubocop-hq/rubocop/issues/8489): Exclude method `respond_to_missing?` from `OptionalBooleanParameter` cop. ([@em-gazelle][])

## 0.90.0 (2020-09-01)

Expand Down Expand Up @@ -4871,3 +4872,4 @@
[@Skipants]: https://github.com/Skipants
[@sascha-wolf]: https://github.com/sascha-wolf
[@iSarCasm]: https://github.com/iSarCasm
[@em-gazelle]: https://github.com/em-gazelle
3 changes: 3 additions & 0 deletions lib/rubocop/cop/style/optional_boolean_parameter.rb
Expand Up @@ -26,8 +26,11 @@ module Style
class OptionalBooleanParameter < Base
MSG = 'Use keyword arguments when defining method with boolean argument.'
BOOLEAN_TYPES = %i[true false].freeze
METHODS_EXCLUDED = %i[respond_to_missing?].freeze

def on_def(node)
return if METHODS_EXCLUDED.include?(node.method_name)

node.arguments.each do |arg|
next unless arg.optarg_type?

Expand Down
9 changes: 8 additions & 1 deletion spec/rubocop/cop/style/optional_boolean_parameter_spec.rb
Expand Up @@ -42,10 +42,17 @@ def some_method
RUBY
end

it 'does not register an offense when defining method with optonal non-boolean arg' do
it 'does not register an offense when defining method with optional non-boolean arg' do
expect_no_offenses(<<~RUBY)
def some_method(bar = 'foo')
end
RUBY
end

it 'does not register an offense when defining respond_to_missing? method with boolean arg' do
expect_no_offenses(<<~RUBY)
def respond_to_missing?(arg, bar = false)
end
RUBY
end
end

0 comments on commit 2f4a16d

Please sign in to comment.