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

False Failure: Style/MixinUsage: include is used at the top level. Use inside class or module. #6972

Closed
luke-hill opened this issue Apr 26, 2019 · 1 comment · Fixed by #7000
Assignees
Labels

Comments

@luke-hill
Copy link

luke-hill commented Apr 26, 2019

Expected behavior

rubocop doesn't throw any failures for the code snippet below

Actual behavior

rubocop throws 1 failure

C: Style/MixinUsage: include is used at the top level. Use inside class or module.
      include Spec::Rails::Matchers if defined?(Spec::Rails::Matchers)
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Steps to reproduce the problem

class CopTest; end

[CopTest].each do |klass|
  klass.class_eval do
    include Spec::Matchers
    include Spec::Rails::Matchers if defined?(Spec::Rails::Matchers)
  end
end

RuboCop version

$ [bundle exec] rubocop -V
0.66.0 (using Parser 2.6.2.1, running on ruby 2.5.3 x86_64-linux)

The issue is the if statement. As you can see when running this that the include Spec::Matchers line doesn't complain.

@koic
Copy link
Member

koic commented Apr 29, 2019

@Darhazer I opened a PR #7000. Would you please review the PR?

koic added a commit to koic/rubocop that referenced this issue Apr 30, 2019
Fixes rubocop#6972

This PR fixes a false positive for `Style/MixinUsage` when using
inside block and `if` condition is after `include`.
Darhazer added a commit that referenced this issue Apr 30, 2019
…_usage

[Fix #6972] Fix a false positive for `Style/MixinUsage`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants