misogi / vscode-ruby-rubocop

Rubocop extension for Visual Studio Code
https://marketplace.visualstudio.com/items/misogi.ruby-rubocop
MIT License
137 stars 68 forks source link

ruby-rubocop does not pick the proper Ruby and RuboCop versions #155

Closed noraworld closed 3 years ago

noraworld commented 3 years ago

I’ve got an error while executing RuboCop via ruby-rubocop from VS Code.

cannot load such file -- rubocop-rails
/Users/noraworld/.anyenv/envs/rbenv/versions/2.7.1/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:92:in `require'
/Users/noraworld/.anyenv/envs/rbenv/versions/2.7.1/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:92:in `require'
/Users/noraworld/.anyenv/envs/rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.88.0/lib/rubocop/config_loader_resolver.rb:15:in `block in resolve_requires'
/Users/noraworld/.anyenv/envs/rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.88.0/lib/rubocop/config_loader_resolver.rb:11:in `each'
/Users/noraworld/.anyenv/envs/rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.88.0/lib/rubocop/config_loader_resolver.rb:11:in `resolve_requires'
/Users/noraworld/.anyenv/envs/rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.88.0/lib/rubocop/config_loader.rb:43:in `load_file'
/Users/noraworld/.anyenv/envs/rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.88.0/lib/rubocop/config_loader.rb:103:in `configuration_from_file'
/Users/noraworld/.anyenv/envs/rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.88.0/lib/rubocop/config_store.rb:58:in `for_dir'
/Users/noraworld/.anyenv/envs/rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.88.0/lib/rubocop/config_store.rb:33:in `for_file'
/Users/noraworld/.anyenv/envs/rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.88.0/lib/rubocop/runner.rb:132:in `file_offense_cache'
/Users/noraworld/.anyenv/envs/rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.88.0/lib/rubocop/runner.rb:120:in `file_offenses'
/Users/noraworld/.anyenv/envs/rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.88.0/lib/rubocop/runner.rb:111:in `process_file'
/Users/noraworld/.anyenv/envs/rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.88.0/lib/rubocop/runner.rb:90:in `block in each_inspected_file'
/Users/noraworld/.anyenv/envs/rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.88.0/lib/rubocop/runner.rb:89:in `each'
/Users/noraworld/.anyenv/envs/rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.88.0/lib/rubocop/runner.rb:89:in `reduce'
/Users/noraworld/.anyenv/envs/rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.88.0/lib/rubocop/runner.rb:89:in `each_inspected_file'
/Users/noraworld/.anyenv/envs/rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.88.0/lib/rubocop/runner.rb:78:in `inspect_files'
/Users/noraworld/.anyenv/envs/rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.88.0/lib/rubocop/runner.rb:39:in `run'
/Users/noraworld/.anyenv/envs/rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.88.0/lib/rubocop/cli/command/execute_runner.rb:21:in `execute_runner'
/Users/noraworld/.anyenv/envs/rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.88.0/lib/rubocop/cli/command/execute_runner.rb:13:in `run'
/Users/noraworld/.anyenv/envs/rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.88.0/lib/rubocop/cli/command.rb:10:in `run'
/Users/noraworld/.anyenv/envs/rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.88.0/lib/rubocop/cli/environment.rb:17:in `run'
/Users/noraworld/.anyenv/envs/rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.88.0/lib/rubocop/cli.rb:65:in `run_command'
/Users/noraworld/.anyenv/envs/rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.88.0/lib/rubocop/cli.rb:72:in `execute_runners'
/Users/noraworld/.anyenv/envs/rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.88.0/lib/rubocop/cli.rb:41:in `run'
/Users/noraworld/.anyenv/envs/rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.88.0/exe/rubocop:13:in `block in <top (required)>'
/Users/noraworld/.anyenv/envs/rbenv/versions/2.7.1/lib/ruby/2.7.0/benchmark.rb:308:in `realtime'
/Users/noraworld/.anyenv/envs/rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/rubocop-0.88.0/exe/rubocop:12:in `<top (required)>'
/Users/noraworld/.anyenv/envs/rbenv/versions/2.7.1/bin/rubocop:23:in `load'
/Users/noraworld/.anyenv/envs/rbenv/versions/2.7.1/bin/rubocop:23:in `<main>'

I know the reason why this error happens. In this project, the versions of Ruby and RuboCop are 2.5.7 and 0.80.1 respectively. However, ruby-rubocop executes RuboCop with Ruby version 2.7.1 and RuboCop version 0.88.0.

The problem is that it uses the wrong versions of Ruby and RuboCop. I’ve checked the followings.

cd <THIS_PROJECT>
ruby -v
ruby 2.5.7p206 (2019-10-01 revision 67816) [x86_64-darwin20]
bundle exec rubocop -v
0.80.1
bundle exec rubocop <FILE>
Inspecting 1 file
.

1 file inspected, no offenses detected

How can I fix this?

Here’s my current environment.

noraworld commented 3 years ago

ruby-rubocop configuration is the following.

ruby-rubocop configuration

I don’t want to specify the config file path and execute path because:

noraworld commented 3 years ago

I will close this issue because this project appears not to be maintained.

I found another VS Code extension that provides the same features as this.

Ruby - Visual Studio Marketplace

I installed it, added the settings as follow, and then, yeah, I was able to enable RuboCop across multiple Ruby versions on VS Code.

"ruby.useBundler": true,
"ruby.useLanguageServer": true,
"ruby.lint": {
    "rubocop": {
        "useBundler": true,
        "except": ["Metrics"] // because it is annoying that it puts wavy lines to all lines in those methods
    }
},
"ruby.format": "rubocop",

I hope this is helpful those who is facing the same issue.