Skip to content
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

Unexpected glob behavior when including files #12695

Closed
dduugg opened this issue Feb 16, 2024 · 2 comments
Closed

Unexpected glob behavior when including files #12695

dduugg opened this issue Feb 16, 2024 · 2 comments
Labels

Comments

@dduugg
Copy link
Contributor

dduugg commented Feb 16, 2024

In the brew repo, I would like to our non-vendored .rbi files (Sorbet's "Ruby Interface" files, written in Ruby) to be covered by RuboCop. However, I just noticed that our configuration wasn't behaving as expected.

In particular, I'm seeing that this configuration:

AllCops:
  Include:
    - "**/*.rbi"

is less inclusive than this one:

AllCops:
  Include:
    - "Homebrew/**/*.rbi"

As a demonstration, this PR leads to these violations, although there are no violations on the base branch.


Expected behavior

**/*.rbi should be a superset of Homebrew/**/*.rbi

Actual behavior

Homebrew/**/*.rbi includes files that **/*.rbi does not (I'm not actually sure the latter is including any files)

Steps to reproduce the problem

See the config file and PR run linked above. I don't have a more minimal repro available, but could attempt one if needed.

RuboCop version

Include the output of rubocop -V or bundle 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:

1.60.2 (using Parser 3.3.0.5, rubocop-ast 1.30.0, running on ruby 3.1.4) [arm64-darwin20]
with:
    rubocop-ast (1.30.0)
    rubocop-capybara (2.20.0)
    rubocop-factory_bot (2.25.1)
    rubocop-md (1.2.2)
    rubocop-performance (1.20.2)
    rubocop-rspec (2.26.1)
    rubocop-sorbet (0.7.7)
@jonas054
Copy link
Collaborator

jonas054 commented Feb 24, 2024

What ultimately causes this behavior is that File.fnmatch('../**/*.irb', 'Homebrew/file.irb', File::FNM_PATHNAME | File::FNM_EXTGLOB) returns false. This is a bit unexpected if you ask me, but that's how it is and we must adapt to the fact. I'll try to provide a solution.

The ../ in the pattern - in case you're wondering - comes from the fact that Library/Homebrew/.rubocop.yml inherits from ../.rubocop.yml and in configuration files that begin with .rubocop, we interpret include/exclude paths as being relative to the file itself, rather than relative to the current directory.

@koic koic closed this as completed in 36370f2 Feb 25, 2024
koic added a commit that referenced this issue Feb 25, 2024
[Fix #12695] Handle Include from inherited file in parent directory
@dduugg
Copy link
Contributor Author

dduugg commented Feb 25, 2024

Thank you‼️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants