VS Code x Rubocop - ruby_executable_hooks: No such file or directory

Environment

  • macOS Monterey (Version 12.1)

  • Ruby 2.6.6

  • Ruby version manager: RVM

  • Editor: VS Code

To Reproduce:

I've installed rubocop gem in my app and add an extension ruby-rubocop in my VS Code.

Open VS Code and see the warning messages below. This caused Rubocop cannot execute correctly.

/Users/lynnbright/.rvm/gems/ruby-2.6.6/bin/rubocop returns empty output! please check configuration.

env: ruby_executable_hooks: No such file or directory

How to solve it:

  1. Locate Rubocup:
$ which rubocup
# /Users/lynnbright/.rvm/gems/ruby-2.6.6/bin/rubocop

2. Replace bin with wrappers.

/Users/lynnbright/.rvm/gems/ruby-2.6.6/wrappers/rubocop

3. Go to your VS Code Settings page. You can press command + ,.

4. Search rubocup or Find the tab User > Extensions > Ruby-Rubocop > Ruby › Rubocop: Execute Path.

5. Paste Rubocop’s executable path:

/Users/lynnbright/.rvm/gems/ruby-2.6.6/wrappers/

6. Restart your VS Code.

7. The warning messages might disappear and your Rubocup can execute correctly now!


Reference