From 221451e6a3b7512ffa871cb540569caf55d5b33a Mon Sep 17 00:00:00 2001 From: em-gazelle Date: Tue, 15 Sep 2020 21:11:37 -0400 Subject: [PATCH] [#8489](https://github.com/rubocop-hq/rubocop/issues/8489) Exclude method respond_to_missing? from OptionalBooleanParameter cop. --- CHANGELOG.md | 2 ++ lib/rubocop/cop/style/optional_boolean_parameter.rb | 3 +++ .../rubocop/cop/style/optional_boolean_parameter_spec.rb | 9 ++++++++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 23a1fc9dcad..f1ff90e5dbb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) @@ -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 diff --git a/lib/rubocop/cop/style/optional_boolean_parameter.rb b/lib/rubocop/cop/style/optional_boolean_parameter.rb index 58573956ea8..9a31c3cd10d 100644 --- a/lib/rubocop/cop/style/optional_boolean_parameter.rb +++ b/lib/rubocop/cop/style/optional_boolean_parameter.rb @@ -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? diff --git a/spec/rubocop/cop/style/optional_boolean_parameter_spec.rb b/spec/rubocop/cop/style/optional_boolean_parameter_spec.rb index ff0bba53320..d207a1e9584 100644 --- a/spec/rubocop/cop/style/optional_boolean_parameter_spec.rb +++ b/spec/rubocop/cop/style/optional_boolean_parameter_spec.rb @@ -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