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 finds .rubocop.yml in parent directories #536
Comments
Yes, that's by design. This behavior is governed by two principles.
The reason for (1) is that we don't want The purpose of the design is to make configuration of RuboCop work "as expected". I'm sorry to see that it didn't for you in this case, but I'm not sure how we can change it without breaking other behavior. A work-around that lets you inspect excluded files is to give them as explicit arguments. For example:
|
@jonas054 Maybe you could add more information on the subject to the README? |
Sure. |
I understand the rationale for point number 2, but I wasn't suggesting to stop that behavior. The only difference would be that if you started it deep in a sub-tree that you stop after you saw the first .rubocop.yml file. It doesn't seem like it is a common use case to have multiple different per directory .rubocop.yml files. In fact, I think that is the source of confusion for me. My guess is that the vast majority of all projects have a single .rubocop.yml file. Personally, if I see a rubocop failure I want to look in one place and see all of the rule modifications. I don't want to have to recursively search my project and gather up all of the files to concatenate the combined configuration. That just seems like overuse of configuration. |
This is for rubocop#536, but we may want to keep the issue open for discussion a while longer. Move the sentence about what the configuration file is for, to the first paragraph. Make the example .rubocop.yml file more realistic by setting parameter values that are different from the default ones. Clarify the note about AllCops/Excludes. Make first paragraph under "Including/Excluding files" more clear and simple. Make "Inheritance" a subchapter, and try to use the word "inherit" rather than "include" when describing inherit_from. Replace the word folder with directory so we use the same nomenclature throughout the README. Make "Disabling Cops within Source Code" its own subchapter, not under "Configuration", since it has nothing to do with .rubocop.yml.
Before continuing to discuss how to allow inspection of files that would normally be excluded, I want to give some background so we're all on the same page. The reason for the special handling of The algorithm RuboCop follows to determine which files to inspect is this:
|
So if I understand your proposal correctly, @b4hand, you want This has an unwanted implication that would have to be fixed. A vendor project with a |
I know this is super old... but it might be nice if it was configurable to stop the traversal through parent directories. I just had some confusing/surprising behavior because I accidentally had a .rubocop file in my home directory. |
@agibralter Your problem only occurs if you have no
|
using |
I just ran into this behavior, and also found it surprising that the first
@jonas054 can you elaborate? I don't understand your example why taking the first Are you saying that it's intended to have multiple nested |
Yes, that is supported. I don't think that feature is used much, having multiple
Think of vendor directories, i.e. code from other projects being copied in to your project. If you say in your project that you don't want to inspect the files in vendor directories, the Note that it's only |
@jonas054 Could you give me a practical example in which the current behaviour is expected? Say I have a layout like the one mentioned originally
Whereas if you run rubocop from the projec1 root folder, you do want your exclusions to be applied, if for some reason you explicitly switch to the vendored project2 in order to run rubocop, I can't think of a reason why it shouldn't go ahead and inspect the files and disregard exclusions further up. You mentioned #288 as the original motivation for the current special handling of For what it's worth, I created at PR that fixes this: #8176. |
From the perspective of running RuboCop on the command line, standing in different directories, you may have a point. But it would mean that we have to consider current directory in the exclusion logic, and that logic is already pretty complex. Wouldn't it affect RuboCop editor integration if current directory is added as a factor in the inspection algorithm? |
You're right, although I made some testing in #8176 when the initial approach was to use CWD, and results seemed either the same or superior. But I only checked my particular integration. Anyways, I dropped the CWD approach because that reason: it felt potentially breaking even if I couldn't figure out how. |
I have a project that vendors in another project using git submodules both of which I work inside. So my file system looks something like this:
Inside src/project1/.rubocop.yml I exclude the vendor directory using
vendor/**
. Unfortunately, this means that when I run rubocop from within project2 it picks up the Exclude and then rubocop says it is "Inspecting 0 files". This is not what I intended. I simply don't want to see rubocop issues for vendor when I'm building within project1, but I do want to see them when I'm building within project2. Here's some output from rubocop --debug:That last line is the issue. Is there a reason rubocop walks the directory tree up looking for configuration higher than my current invocation path even when it has already found a
.rubocop.yml
?The text was updated successfully, but these errors were encountered: