Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix #6972] Fix a false positive for Style/MixinUsage #7000

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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