Enable rubocop in VScode

Nikhil Mohadikar
2 min readMar 6, 2023

Linting errors can help improve code quality when it comes to writing a code in Ruby. We usually use Rubocop gem to check the linting errors while writing the code. Running the rubocop command for each file we change can be a little tiresome while working on big projects.

It’s always better to enable to rubocop warning in the editor. Below are the steps you can follow to enable the rubocop in VScode.

1 :- In VScode extension marketplace, search for extension ruby-rubocop

2 :- Install this extension and restart the VScode.

3 :- After restarting, add the below setting in your settings.json file

"ruby.rubocop.configFilePath": "path to .rubocop.yml file",
"ruby.rubocop.executePath": "path to rubocop executable",
"ruby.rubocop.useBundler": true // use rubocop for formatting

4 :- .rubocop.yml file is usually in the root directory of your project.

My rubocop.yml path looks like below

"/Users/nikhilmohadikar/dev/rails_workspace/caffeine_zombie/.rubocop.yml"

5:- Below command will give you the path to the rubocop executable. Execute the below command in your terminal. ( For RVM, make sure you are using a right gemset while using the below command )

which rubocop 

My Rubocop executable path looks something like this

"/Users/nikhilmohadikar/.rvm/gems/ruby-3.1.3@caffeine_zombie/bin/"

5 :- Save the settings and open any .rb file and click Ctrl + s to see the rubocop warnings

6:- If you see error saying rubocop command returns empty output. Close the VScode. Navigate to your project root folder via terminal and open project in VScode using command below

code .

--

--