Skip to content

Commit

Permalink
Merge pull request #7000 from koic/fix_false_positive_for_style_mixin…
Browse files Browse the repository at this point in the history
…_usage

[Fix #6972] Fix a false positive for `Style/MixinUsage`
  • Loading branch information
Darhazer committed Apr 30, 2019
2 parents 5d304d0 + 11b87ca commit ce27c89
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/ast/node/mixin/method_dispatch_node.rb
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions spec/rubocop/cop/style/mixin_usage_spec.rb
Expand Up @@ -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))
Expand Down

0 comments on commit ce27c89

Please sign in to comment.