-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Cop from RuboCop takes precedence over cop with the same name (but different department) from extension and the require
is done in an inherited file/gem
#5251
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
Comments
@bquorning @Darhazer Can you confirm this? |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution and understanding! |
After upgrading
and
|
Hello. 👋 I'm seeing this issue as well. Here's the contents of my Configurationinherit_gem:
caliber: config/all.yml
require:
- rubocop-rails
RSpec/FilePath:
CustomTransform:
URLs: urls If you are curious how the Caliber gem works, here is the configuration being used and inherited from the gem. Interestingly, when I add this statement to the configuration (as shown above): require:
- rubocop-rails ...and then run Error Output
So when adding the Debug Details
Here's my environment when running
Workaround After studying Rémy's bug reproduction -- as stated in this issue -- I was able to use this configuration as a workaround where I have to re-require all gem dependencies: Workaround Solution# You have to re-require all dependencies even though the Caliber gem does this for you.
require:
- rubocop-performance
- rubocop-rake
- rubocop-rails
- rubocop-rspec
inherit_gem:
caliber: config/all.yml
RSpec/FilePath:
CustomTransform:
URLs: urls |
Just stumbled upon this one. I was not aware of the workaround using an additional In case this helps (also debugging): Another workaround was to have the configuration inside Can confirm that this is still the case for rubocop 1.39.0. |
Attempting a fix in #11216. Hope this does not break anything else 🙈 |
Ingredients for the edge-case: * .rubocop.yml inherits another config (inherit_from/inherit_gem) * .other config requires an additional gem (e.g. rubocop-rspec) * .rubocop.yml configures a cop defined in additional gem (e.g. RSpec/VariableName) whose name already exists in rubocop (e.g. Naming/VariableName) What would have happened before is that during the call of add_missing_namespaces, the registry would have replaced the configuration of the RSpec/VariableName with Naming/VariableName, because that's the only cop that it knew at that point. By changing the call order we make sure that requires of external files are resolved before letting the registry replace badge names.
Ingredients for the edge-case: * .rubocop.yml inherits another config (inherit_from/inherit_gem) * .other config requires an additional gem (e.g. rubocop-rspec) * .rubocop.yml configures a cop defined in additional gem (e.g. RSpec/VariableName) whose name already exists in rubocop (e.g. Naming/VariableName) What would have happened before is that during the call of add_missing_namespaces, the registry would have replaced the configuration of the RSpec/VariableName with Naming/VariableName, because that's the only cop that it knew at that point. By changing the call order we make sure that requires of external files are resolved before letting the registry replace badge names.
Uh oh!
There was an error while loading. Please reload this page.
First of all, thanks for this awesome project!
I've encountered a bug where we're using a gem to define common rules for multiple projects and the
require
is done in the gem.Then in a project that uses this gem, I wanted to disable the
RSpec/FilePath
cop.That wasn't working until I added
in the
.rubocop.yml
of my project.I've set up a reproduction repo here: https://github.com/rymai/reproduce-rubocop-bug
Expected behavior
require
,FilePath
,rubocop
definesRails/FilePath
andrubocop-rspec
definesRSpec/FilePath
)Actual behavior
The rules that act on the extension cop isn't taken in account.
Steps to reproduce the problem
See https://github.com/rymai/reproduce-rubocop-bug.
git clone https://github.com/rymai/reproduce-rubocop-bug.git
cd reproduce-rubocop-bug
bundle install
bundle exec rubocop -c .rubocop-inherit-from-gem.yml --show-cops RSpec/FilePath
orbundle exec rubocop -c .rubocop-inherit-from-file.yml --show-cops RSpec/FilePath
Enabled: true
instead ofEnabled: false
Work-around
You can work-around this bug by re-requiring the extension in the final RuboCop config file.
RuboCop version
also,
rubocop-rspec (1.21.0)
.The text was updated successfully, but these errors were encountered: