Skip to content

Commit

Permalink
[#8489](#8489) Exclude method respond_to_missing? from OptionalBoolea…
Browse files Browse the repository at this point in the history
…nParameter cop.
  • Loading branch information
em-gazelle authored and mergify[bot] committed Sep 16, 2020
1 parent 07c21d3 commit 221451e
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 @@ -54,6 +54,7 @@
* [#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][])
* [#8663](https://github.com/rubocop-hq/rubocop/issues/8663): Fix multiple autocorrection bugs with `Style/ClassMethodsDefinitions`. ([@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 @@ -4881,3 +4882,4 @@
[@sascha-wolf]: https://github.com/sascha-wolf
[@fsateler]: https://github.com/fsateler
[@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 221451e

Please sign in to comment.