diff --git a/CHANGELOG.md b/CHANGELOG.md index 8cdf0322749..a4d9bf1dbb9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ * [#6996](https://github.com/rubocop-hq/rubocop/pull/6996): Fix a false positive for `Style/RedundantFreeze` when freezing the result of `String#*`. ([@bquorning][]) * [#6998](https://github.com/rubocop-hq/rubocop/pull/6998): Fix autocorrect of `Naming/RescuedExceptionsVariableName` to also rename all references to the variable. ([@Darhazer][]) * [#6992](https://github.com/rubocop-hq/rubocop/pull/6992): Fix unknown default configuration for `Layout/IndentFirstParameter` cop. ([@drenmi][]) +* [#6972](https://github.com/rubocop-hq/rubocop/issues/6972): Fix a false positive for `Style/MixinUsage` when using inside block and `if` condition is after `include`. ([@koic][]) ## 0.68.0 (2019-04-29) diff --git a/lib/rubocop/ast/node/mixin/method_dispatch_node.rb b/lib/rubocop/ast/node/mixin/method_dispatch_node.rb index bb6e6297922..f9a503b7ecd 100644 --- a/lib/rubocop/ast/node/mixin/method_dispatch_node.rb +++ b/lib/rubocop/ast/node/mixin/method_dispatch_node.rb @@ -212,7 +212,7 @@ def binary_operation? def_node_matcher :macro_scope?, <<-PATTERN {^{({sclass class module block} ...) class_constructor?} - ^^{({sclass class module block} ... (begin ...)) class_constructor?} + ^^{({sclass class module block} ... ({begin if} ...)) class_constructor?} ^#macro_kwbegin_wrapper? #root_node?} PATTERN diff --git a/spec/rubocop/cop/style/mixin_usage_spec.rb b/spec/rubocop/cop/style/mixin_usage_spec.rb index 6cac3cd9bdc..40536aabfd7 100644 --- a/spec/rubocop/cop/style/mixin_usage_spec.rb +++ b/spec/rubocop/cop/style/mixin_usage_spec.rb @@ -62,6 +62,15 @@ class C RUBY end + it 'does not register an offense when using inside block ' \ + 'and `if` condition is after `include`' do + expect_no_offenses(<<-RUBY.strip_indent) + klass.class_eval do + include M if defined?(M) + end + RUBY + end + it "doesn't register an offense when `include` call is a method argument" do expect_no_offenses(<<-RUBY.strip_indent) do_something(include(M))