Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby-Rubocop not working on vscode

/Users/me/.rbenv/versions/2.5.1/lib/ruby/2.5.0/rubygems.rb:289:in ``find_spec_for_exe': can't find gem rubocop (>= 0.a) with executable rubocop (Gem::GemNotFoundException) from /Users/me/.rbenv/versions/2.5.1/lib/ruby/2.5.0/rubygems.rb:308:in ``activate_bin_path' from /Users/me/.rbenv/versions/2.5.1/bin/rubocop:23:in'

This is the error I keep getting whenever I type something. Does anyone know how to fix this problem?

like image 471
smmr14 Avatar asked May 17 '18 22:05

smmr14


People also ask

How do I get Rubocop to work on VSCode?

Go on VSCode Marketplace and clic on the Download Extension button. Install the extension manually from the CLI: code --install-extension misogi. ruby-rubocop-0.8.

Can I use VSCode for Ruby?

VSCode supports multiple languages like C, C++, Python, Ruby, etc. it includes features like debugging, syntax highlighting, intelligent code completion, snippets, code refactoring, and embedded Git.

What is Rubocop in Ruby?

RuboCop is a Ruby static code analyzer (a.k.a. linter ) and code formatter. Out of the box it will enforce many of the guidelines outlined in the community Ruby Style Guide. Apart from reporting the problems discovered in your code, RuboCop can also automatically fix many of them for you.


2 Answers

After many agonising hours and reading other solutions I finally deduce that the answer was in installing Rubocop from the root. Below steps worked when I tried. You first need to go the root in your terminal. Install Rubocop then find the path and add it to the execute path in Rubocop settings

$ cd ~
$ gem install rubocop
$ which rubocop
Paste location given in Ruby-Rubocop configuration settings > Execute Path
/Users/username/.rvm/gems/ruby-2.6.1/bin/
like image 153
clarkesh Avatar answered Oct 12 '22 23:10

clarkesh


I can propose you 2 solutions because I had experienced the same problem:

  • For me installing the bundler with sudo -> sudo gem install bundler fix the issue.

  • Also it can be a mistake coming from you RubyGems version. It seems like ruby -v2.5 has a compatible problem with RubyGems -v2.7.3. So try upgrading the RubyGems to -v2.7.4 using the gem update --system command.

like image 42
radoAngelov Avatar answered Oct 12 '22 23:10

radoAngelov