rubocop on VScode not working.Error "rubocop is not executable" rubocop on VScode not working.Error "rubocop is not executable" ruby ruby

rubocop on VScode not working.Error "rubocop is not executable"


The accepted answer didn't work for me. However, I did find a comment by jdarnok on this GitHub issue that worked for me.

First, to get the user's path of the program file, I ran:

rbenv which rubocop

which gave me this result:

/Users/<your username>/.rbenv/versions/2.6.2/gemsets/Rails4.2_EnergyLink/bin/rubocop

Then I ran:

which rubocop

which gave me this result:

/Users/<your username>/.rbenv/shims/rubocop

SOLUTION

In the settings of VS Code under Ruby > Rubocop: Execute Path I pasted:

/Users/<your username>/.rbenv/shims/

Other potential solutions

This Stackoverflow post refers to a few other potential solutions, such as:

  • Replace bin in the PATH with wrappers
  • Refresh executable hooks
  • Update bundler
  • Update gems


tl;dr

Make sure you installed Rubocop in the first place.

VS Code Rubocop Tutorial

Install Rubocop

gem install rubocop

You can check that it works properly like this:

rubocop -v

Install VS Code extension

Search for ruby-rubocop in the marketplace and install it.

Install Rubocop VS Code marketplace

Configure Rubocop for your project

Add a .rubocop.yml file to your project's root. You can see all the configuration options and how such a file should look like in the default config file. Be aware that if there are outdated or wrong rules in the file, you will get an error and Rubocop won't work. VS Code will alert you about this:

Rubocop config errors


Take a look to the configuration docs.

{  // If not specified searches for 'rubocop' executable available on PATH (default and recommended)  "ruby.rubocop.executePath": "",  ...}

So, by default executePath won't be setted, because it's expecting you to have the rubocop executable within your PATH.

In a simply way, there are two things you can do, add the rubocop executable path to your PATH, or add it within the package options.

You can check for the rubocop executable directory with which rubocop (then copy and paste).