Closed javian closed 6 years ago
This does indeed sound interesting. I would like to help investigate if this is a bug on our side.
Running it with
-d
show this
I have made a shallow clone (git clone --depth 1
) of the homebrew repository, but I cannot immediately figure out how you execute RuboCop. I see it is present in the Gemfile in Library/Homebrew/test, but I assume you are running the command somehow from the Library/Homebrew folder?
Can you show me which command to run in the repository, to get the error you’re seeing. Thanks.
Homebrew itself uses two commands to run tests using rubocop brew style
https://github.com/Homebrew/brew/blob/master/Library/Homebrew/style.rb and brew tests
which uses amongst other things such as the gemfile you mentioned and has its own ruby version with a gem repository. brew style
in its current form is not affected since it uses --config
to load a single config which I'm about to change in the https://github.com/Homebrew/brew/pull/5043 .
This is however not relevant to how I run it at the moment since I'm using the regular rubocop
executable from the gem so imagine I've simply ran gem install rubocop rubocop-rspec
and then do
➜ Homebrew git:(master) ✗ pwd
/usr/local/Homebrew/Library/Homebrew
➜ Homebrew git:(master) ✗ rubocop -d
For /usr/local/Homebrew/Library/Homebrew: configuration from /usr/local/Homebrew/Library/Homebrew/.rubocop.yml
Inheriting configuration from /usr/local/Homebrew/Library/.rubocop.yml
Default configuration from /usr/local/lib/ruby/gems/2.5.0/gems/rubocop-0.59.2/config/default.yml
Inheriting configuration from /usr/local/lib/ruby/gems/2.5.0/gems/rubocop-0.59.2/config/enabled.yml
Inheriting configuration from /usr/local/lib/ruby/gems/2.5.0/gems/rubocop-0.59.2/config/disabled.yml
AllCops/Exclude configuration from /usr/local/Homebrew/Library/.rubocop.yml
For /usr/local/Homebrew/Library/Homebrew/test/support/fixtures/cask: configuration from /usr/local/Homebrew/Library/Homebrew/test/.rubocop.yml
configuration from /usr/local/lib/ruby/gems/2.5.0/gems/rubocop-rspec-1.29.1/config/default.yml
configuration from /usr/local/lib/ruby/gems/2.5.0/gems/rubocop-rspec-1.29.1/config/default.yml
Inheriting configuration from /usr/local/Homebrew/Library/Homebrew/.rubocop.yml
Inheriting configuration from /usr/local/Homebrew/Library/.rubocop.yml
Inheriting configuration from /usr/local/Homebrew/Library/Homebrew/test/.rubocop_todo.yml
AllCops/Exclude configuration from /usr/local/Homebrew/Library/.rubocop.yml
Unprocessable file /usr/local/Homebrew/Library/Homebrew/test/support/fixtures/elf/hello: ArgumentError, invalid byte sequence in UTF-8
Inspecting 702 files
Scanning /usr/local/Homebrew/Library/Homebrew/reinstall.rb
.Scanning /usr/local/Homebrew/Library/Homebrew/update_migrator.rb
.Scanning /usr/local/Homebrew/Library/Homebrew/PATH.rb
.Scanning /usr/local/Homebrew/Library/Homebrew/commands.rb
.Scanning /usr/local/Homebrew/Library/Homebrew/formula_assertions.rb
.Scanning /usr/local/Homebrew/Library/Homebrew/pkg_version.rb
.Scanning /usr/local/Homebrew/Library/Homebrew/dependencies.rb
.Scanning /usr/local/Homebrew/Library/Homebrew/descriptions.rb
.Scanning /usr/local/Homebrew/Library/Homebrew/brew.rb
.Scanning /usr/local/Homebrew/Library/Homebrew/install_renamed.rb
.Scanning /usr/local/Homebrew/Library/Homebrew/keg_relocate.rb
.Scanning /usr/local/Homebrew/Library/Homebrew/load_path.rb
.Scanning /usr/local/Homebrew/Library/Homebrew/install.rb
.Scanning /usr/local/Homebrew/Library/Homebrew/help.rb
.Scanning /usr/local/Homebrew/Library/Homebrew/formula_installer.rb
.Scanning /usr/local/Homebrew/Library/Homebrew/tab.rb
.Scanning /usr/local/Homebrew/Library/Homebrew/metafiles.rb
.Scanning /usr/local/Homebrew/Library/Homebrew/migrator.rb
.Scanning /usr/local/Homebrew/Library/Homebrew/software_spec.rb
An error occurred while FactoryBot/CreateList cop was inspecting /usr/local/Homebrew/Library/Homebrew/software_spec.rb:1:0.
undefined method `to_sym' for nil:NilClass
/usr/local/lib/ruby/gems/2.5.0/gems/rubocop-0.59.2/lib/rubocop/cop/mixin/configurable_enforced_style.rb:65:in `style'
/usr/local/lib/ruby/gems/2.5.0/gems/rubocop-rspec-1.29.1/lib/rubocop/cop/rspec/factory_bot/create_list.rb:58:in `on_send'
/usr/local/lib/ruby/gems/2.5.0/gems/rubocop-0.59.2/lib/rubocop/cop/commissioner.rb:58:in `block (2 levels) in trigger_responding_cops'
/usr/local/lib/ruby/gems/2.5.0/gems/rubocop-0.59.2/lib/rubocop/cop/commissioner.rb:106:in `with_cop_error_handling'
/usr/local/lib/ruby/gems/2.5.0/gems/rubocop-0.59.2/lib/rubocop/cop/commissioner.rb:57:in `block in trigger_responding_cops'
/usr/local/lib/ruby/gems/2.5.0/gems/rubocop-0.59.2/lib/rubocop/cop/commissioner.rb:56:in `each'
/usr/local/lib/ruby/gems/2.5.0/gems/rubocop-0.59.2/lib/rubocop/cop/commissioner.rb:56:in `trigger_responding_cops'
(I've removed the rest here, can include it if necessary)
I get an error about some missing “backports” file when running RuboCop:
Library/Homebrew ‹2.5.1p57› ‹master› » pwd
/Users/bquorning/Code/homebrew/Library/Homebrew
Library/Homebrew ‹2.5.1p57› ‹master› » rubocop
cannot load such file -- backports/2.4.0/string/match
/Users/bquorning/.rubies/ruby-2.5.1/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
/Users/bquorning/.rubies/ruby-2.5.1/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
/Users/bquorning/Code/homebrew/Library/Homebrew/extend/string.rb:2:in `<top (required)>'
/Users/bquorning/.rubies/ruby-2.5.1/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
/Users/bquorning/.rubies/ruby-2.5.1/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
/Users/bquorning/Code/homebrew/Library/Homebrew/rubocops/extend/formula_cop.rb:10:in `<top (required)>'
/Users/bquorning/.rubies/ruby-2.5.1/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
/Users/bquorning/.rubies/ruby-2.5.1/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
/Users/bquorning/Code/homebrew/Library/Homebrew/rubocops/formula_desc_cop.rb:1:in `<top (required)>'
/Users/bquorning/.rubies/ruby-2.5.1/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
/Users/bquorning/.rubies/ruby-2.5.1/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
/Users/bquorning/Code/homebrew/Library/Homebrew/rubocops.rb:3:in `<top (required)>'
/Users/bquorning/.rubies/ruby-2.5.1/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
/Users/bquorning/.rubies/ruby-2.5.1/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
/Users/bquorning/.gem/ruby/2.5.1/gems/rubocop-0.59.2/lib/rubocop/config_loader_resolver.rb:13:in `block in resolve_requires'
/Users/bquorning/.gem/ruby/2.5.1/gems/rubocop-0.59.2/lib/rubocop/config_loader_resolver.rb:11:in `each'
/Users/bquorning/.gem/ruby/2.5.1/gems/rubocop-0.59.2/lib/rubocop/config_loader_resolver.rb:11:in `resolve_requires'
/Users/bquorning/.gem/ruby/2.5.1/gems/rubocop-0.59.2/lib/rubocop/config_loader.rb:43:in `load_file'
/Users/bquorning/.gem/ruby/2.5.1/gems/rubocop-0.59.2/lib/rubocop/config_loader_resolver.rb:139:in `block in base_configs'
/Users/bquorning/.gem/ruby/2.5.1/gems/rubocop-0.59.2/lib/rubocop/config_loader_resolver.rb:138:in `map'
/Users/bquorning/.gem/ruby/2.5.1/gems/rubocop-0.59.2/lib/rubocop/config_loader_resolver.rb:138:in `base_configs'
/Users/bquorning/.gem/ruby/2.5.1/gems/rubocop-0.59.2/lib/rubocop/config_loader_resolver.rb:22:in `resolve_inheritance'
/Users/bquorning/.gem/ruby/2.5.1/gems/rubocop-0.59.2/lib/rubocop/config_loader.rb:49:in `load_file'
/Users/bquorning/.gem/ruby/2.5.1/gems/rubocop-0.59.2/lib/rubocop/config_loader.rb:82:in `configuration_from_file'
/Users/bquorning/.gem/ruby/2.5.1/gems/rubocop-0.59.2/lib/rubocop/config_store.rb:44:in `for'
/Users/bquorning/.gem/ruby/2.5.1/gems/rubocop-0.59.2/lib/rubocop/cli.rb:187:in `apply_default_formatter'
/Users/bquorning/.gem/ruby/2.5.1/gems/rubocop-0.59.2/lib/rubocop/cli.rb:40:in `run'
/Users/bquorning/.gem/ruby/2.5.1/gems/rubocop-0.59.2/exe/rubocop:13:in `block in <top (required)>'
/Users/bquorning/.rubies/ruby-2.5.1/lib/ruby/2.5.0/benchmark.rb:308:in `realtime'
/Users/bquorning/.gem/ruby/2.5.1/gems/rubocop-0.59.2/exe/rubocop:12:in `<top (required)>'
/Users/bquorning/.gem/ruby/2.5.1/bin/rubocop:23:in `load'
/Users/bquorning/.gem/ruby/2.5.1/bin/rubocop:23:in `<main>'
gem install backports
should take care of that
This indeed is a strange problem. I would recommend against using require
in folder specific RuboCop configuration files. Would that be an ok workaround – to move require: rubocop-rspec
into the topmost .rubocop.yml file?
You might also want to tweak the configuration for AllCops/RSpec/Patterns (https://github.com/rubocop-hq/rubocop-rspec/blob/master/config/default.yml#L2-L6) to only find _spec.rb
files in your test
folder.
I guess that would be the only way to move forward. I would also assume that adding the pattern would also solve the issue since the error only only triggers on files outside of the test/
directory.
It seems to work just fine. I didn't quite get why you recommend against using require
in a folder specific config file though - can you elaborate on that a bit ?
Hmm, I probably need to push it up even one more level in the directory tree since the root config is in the Library
directory.
I didn't quite get why you recommend against using
require
in a folder specific config file though - can you elaborate on that a bit ?
Only to avoid confusion. Using the require
in a folder specific file may lead one to believe that it only applies to the files in that folder – while in fact the required library applies to all files in the project.
It sounds like we found a way to solve the problem, so I’m going to close this issue. Feel free to reopen if you still have issues, or think this should be resolved in another way.
When making some modifications to one of the Homebrew package manager repositories I stumbled upon something that I can't explain. The repo can be found here https://github.com/Homebrew/brew .
The project generally runs Rubocop in the
Homebrew/Library/Homebrew
directory which recursively contains 2 rubocop configuration files where the one in the test directory containsrequire: rubocop-rspec
.With the current set up when rubocop is run in that directory it returns multiple errors looking like this
An error occurred while RSpec/PredicateMatcher cop was inspecting /usr/local/Homebrew/Library/Homebrew/software_spec.rb:417:0. To see the complete backtrace run rubocop -d.
for pretty much every cop thatrubocop-rspec
has to offer.Running it with
-d
show thisIt only barfs on the files matching the pattern
**/*_rspec.rb
that are not in rspec format (ie. outside the test/ directory)So far so good... (or so you might think).
To try and troubleshoot this I tried moving the
require: rubocop-rspec
line to the.rubocop.yml
that's in the directory above thetest/
dir where the rubocop command is executed and lo and behold rubocop executes without any issues.Here you can see that the require line has been moved and rubocop executes without problems so this problem only occurs when the require line it sits in a subdirectory
.rubocop.yml
.I'm currently using the latest of both rubocop* gems
Is this a proper problem or am I doing something wrong ?