Skip to content

Commit 11b87ca

Browse files
committed
[Fix #6972] Fix a false positive for Style/MixinUsage
Fixes #6972 This PR fixes a false positive for `Style/MixinUsage` when using inside block and `if` condition is after `include`.
1 parent 666696b commit 11b87ca

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* [#6996](https://github.com/rubocop-hq/rubocop/pull/6996): Fix a false positive for `Style/RedundantFreeze` when freezing the result of `String#*`. ([@bquorning][])
99
* [#6998](https://github.com/rubocop-hq/rubocop/pull/6998): Fix autocorrect of `Naming/RescuedExceptionsVariableName` to also rename all references to the variable. ([@Darhazer][])
1010
* [#6992](https://github.com/rubocop-hq/rubocop/pull/6992): Fix unknown default configuration for `Layout/IndentFirstParameter` cop. ([@drenmi][])
11+
* [#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][])
1112

1213
## 0.68.0 (2019-04-29)
1314

lib/rubocop/ast/node/mixin/method_dispatch_node.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ def binary_operation?
212212

213213
def_node_matcher :macro_scope?, <<-PATTERN
214214
{^{({sclass class module block} ...) class_constructor?}
215-
^^{({sclass class module block} ... (begin ...)) class_constructor?}
215+
^^{({sclass class module block} ... ({begin if} ...)) class_constructor?}
216216
^#macro_kwbegin_wrapper?
217217
#root_node?}
218218
PATTERN

spec/rubocop/cop/style/mixin_usage_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,15 @@ class C
6262
RUBY
6363
end
6464

65+
it 'does not register an offense when using inside block ' \
66+
'and `if` condition is after `include`' do
67+
expect_no_offenses(<<-RUBY.strip_indent)
68+
klass.class_eval do
69+
include M if defined?(M)
70+
end
71+
RUBY
72+
end
73+
6574
it "doesn't register an offense when `include` call is a method argument" do
6675
expect_no_offenses(<<-RUBY.strip_indent)
6776
do_something(include(M))

0 commit comments

Comments
 (0)