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
RuboCop pulls in .rubocop.yml files from *excluded* directories when specifying explicit target despite using "--force-exclusion" #12667
Labels
Comments
For now, I was able to work this around by adding explicit |
This is a very special case. Quite tricky. But I think it's valid and I'm adding the |
jonas054
added a commit
to jonas054/rubocop
that referenced
this issue
Mar 2, 2024
This change fixes an error that can occur when file names are given explicity on the command line together with `--force-exclusion`. In order to check if the given files are to be excluded, we must load configuration. The problem is that `.rubocop.yml` files in directories with excluded files (e.g. a `vendor` directory) might contain directives that will cause RuboCop to crash, such as `require` with an extension that's not available. What saves us in this situation is that we don't need to load configuration for the file as such. We can load configuration for the current directory instead. The reason is that `Exclude` parameters on the top level are not shadowed by `Exclude` in other `.rubocop.yml` files in subdirectories, as documented here: https://docs.rubocop.org/rubocop/1.60/configuration.html#include-and-exclude-are-relative-to-their-directory The `--ignore-parent-exclusion` flag, if given, changes the situation and we must load the most adjacent `.rubocop.yml` file.
jonas054
added a commit
to jonas054/rubocop
that referenced
this issue
Mar 2, 2024
This change fixes an error that can occur when file names are given explicitly on the command line together with `--force-exclusion`. In order to check if the given files are to be excluded, we must load configuration. The problem is that `.rubocop.yml` files in directories with excluded files (e.g. a `vendor` directory) might contain directives that will cause RuboCop to crash, such as `require` with an extension that's not available. What saves us in this situation is that we don't need to load configuration for the file as such. We can load configuration for the current directory instead. The reason is that `Exclude` parameters on the top level are not shadowed by `Exclude` in other `.rubocop.yml` files in subdirectories, as documented here: https://docs.rubocop.org/rubocop/1.60/configuration.html#include-and-exclude-are-relative-to-their-directory The `--ignore-parent-exclusion` flag, if given, changes the situation and we must load the most adjacent `.rubocop.yml` file.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
At the first sight my issue is similar to #9832, but I was unable to fix it using the solutions that were proposed there.
One of the dependent gems of my project located in
vendor/cache/...
includes its own.rubocop.yml
withrubocop-performance
plugin. Pre-commit hook fails for my project if I update that gem, becauserubocop-performance
is not installed. I double checked thatvendor/**/*
is excluded in the config.The final command generated by the pre-commit hook boils down to:
And excludes in root
.rubocop.yml
look like this:Expected behavior
I'd expect rubocop not to go into the excluded directory when
--force-exclusion
is specified alongside an excluded target. But looks like it may not be possible with the current implementation that checks exclusion only after loading the corresponding config file (in this case, the one that is also located in an ignored directory)Actual behavior
Describe here what actually happened.
Please use
rubocop --debug
when pasting rubocop output as it contains additional information.Steps to reproduce the problem
AllCops/Exclude
configuration.rubocop.yml
next to that excluded file--force-exclusion --debug
.rubocop.yml
is loadedRuboCop version
Include the output of
rubocop -V
orbundle exec rubocop -V
if using Bundler.If you see extension cop versions (e.g.
rubocop-performance
,rubocop-rspec
, and others)output by
rubocop -V
, include them as well. Here's an example:The text was updated successfully, but these errors were encountered: