I have a .rubocop.yml with:
inherit_gem:
intercom-rubocop: "config/rails.yml"
Which inherits from a file with this config:
inherit_from: "default.yml"
Rails:
Enabled: true
Metrics/BlockLength:
Exclude:
- "config/environments/*.rb"
- "config/routes.rb"
- "spec/rails_helper.rb"
Rails/Delegate:
Enabled: false
Style/EmptyLinesAroundBlockBody:
Exclude:
# The DSLs here often benefit from additional whitespace
# that is not appropriate elsewhere.
- "config/routes.rb"
- "spec/**/*"
For example, we exclude Style/EmptyLinesAroundBlockBody from spec directories. When that was in the configuration in the repo it worked, but now that we're inheriting from a gem it no longer excludes those directories, and shows an offense for that cop.
It seems like the RuboCop default configuration has exclusions that get inherited, so I'm not quite clear why this doesn't work. Is it because we're inheriting from a gem? Is this a bug?
I noticed something similar after upgrade to 0.48.0 (0.48.1 as well).
We had in common gem rule
Style/ClassAndModuleChildren:
EnforcedStyle: compact
Exclude:
- "config/application.rb"
and in project rubocop
inherit_gem:
our-internal-gem: .rubocop-base.yml
It was working fine before 0.48.0, but now this file is not excluded
Hmm, we just recently upgraded to 0.48.1, and previously we were on something less than 0.48.0, so I think this was happening to us prior to the latest versions.
I was just starting to look into this, because we have the same problem with a couple of projects and one shared config.yml. However, I can't seem to reproduce it on 0.49.1 or 0.48.1 with the above examples anymore.
I don't have any more time today, but hope to be able to work out a minimal breaking configuration in the next days.
It also doesn't work, when --force-exclusion is used.
fwiw, so far I am only able to reproduce this at work, not at home and I absolutely don't know why.
The shared gem's .rubocop.yml has this content:
---
Metrics/BlockLength:
Exclude:
- config/environments/development.rb
The development.rb has this content:
someblock do
# Insert 25+ lines of random ruby code here
end
The project which includes the shared gem has this .rubocop.yml:
---
inherit_gem:
shared_configs: .rubocop.yml
When I run rubocop -C false -d --force-exclusion config/environments/development.rb it doesn't exclude the rule for the development.rb:
For /home/phansch/code/secret_project: configuration from /home/phansch/code/secret_project/.rubocop.yml
Inheriting configuration from /home/phansch/.rvm/gems/ruby-2.3.1@secret_project/bundler/gems/shared_configs-741fde2ba5e5/.rubocop.yml
Default configuration from /home/phansch/.rvm/gems/ruby-2.3.1@secret_project/gems/rubocop-0.49.1/config/default.yml
Inheriting configuration from /home/phansch/.rvm/gems/ruby-2.3.1@secret_project/gems/rubocop-0.49.1/config/enabled.yml
Inheriting configuration from /home/phansch/.rvm/gems/ruby-2.3.1@secret_project/gems/rubocop-0.49.1/config/disabled.yml
Inspecting 1 file
Scanning /home/phansch/code/secret_project/config/environments/development.rb
C
Offenses:
config/environments/development.rb:5:1: C: Metrics/BlockLength: Block has too many lines. [35/25]
someblock do ...
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
1 file inspected, 1 offense detected
Finished in 0.1417701940081315 seconds
↳ 1
It looks like I fixed the problem by renaming .rubocop.yml in the shared gem to something else. That should fix what @morgoth is describing, too, but probably not the original issue from @brandonweiss.
This is caused by config.rb#L320 that will turn relative exclude paths into absolute paths if the rubocop config file starts with .rubocop. In the case of a shared gem, it would turn the relative exclude path into an absolute path that points inside the gem, instead of inside the main project.
I also found some related issues: #3744 and #3960
Huh. Yeah, the files in my shared gem don't have “rubocop” in their paths, so if that fixed it for @phansch, then it would seem there are actually two bugs causing exclusions not to inherit right?
I will try and write a failing spec for this.
Most helpful comment
It looks like I fixed the problem by renaming
.rubocop.ymlin the shared gem to something else. That should fix what @morgoth is describing, too, but probably not the original issue from @brandonweiss.This is caused by config.rb#L320 that will turn relative exclude paths into absolute paths if the rubocop config file starts with
.rubocop. In the case of a shared gem, it would turn the relative exclude path into an absolute path that points inside the gem, instead of inside the main project.I also found some related issues: #3744 and #3960