Oleg Antonyan
Oleg Antonyan

Reputation: 3113

How to tell Rubocop only look at specific directories?

I want to include only specific directories, and ignore everything else.

This ignores everything

AllCops:
  Include:
    - 'something/**/*.rb'

  Exclude:
    - '**/*'

And this inspects everything

AllCops:
  Include:
    - 'something/**/*.rb'

Upvotes: 5

Views: 2835

Answers (2)

Joshua Pinter
Joshua Pinter

Reputation: 47481

It appears that the latest version (~0.56+) of Rubocop will only include files (or patterns) specified in Include, if you define Include.

This would mean that if all you do is:

AllCops:
  Include:
    - 'something/**/*.rb'

Then only something/**/*.rb will be inspected. It overwrites the default files instead of appending to it.

I think this is new functionality because that's what it's doing for us now and that's not how it was before. Very deceiving for a minor version release.

Upvotes: 4

Oleg Antonyan
Oleg Antonyan

Reputation: 3113

Regex seems to work, but very ugly

AllCops:
  Exclude:
    - !ruby/regexp /^((?!(something|some\/other\/dir)).)*$/

Upvotes: 0

Related Questions