Atom-Editor: Rubocop doesn't work with atom
Asked Answered
A

2

7

I was trying to connect rubocop to atom, but received the error:

linter-registry.js [sm]:144 [Linter] Error running RuboCop Error: /usr/lib/ruby/2.3.0/rubygems/dependency.rb:319:in `to_specs': Could not find 'rubocop' (>= 0.a) among 16 total gem(s) (Gem::LoadError)
Checked in 'GEM_PATH=/home/kurilovichay/.rvm/gems/ruby-2.3.1:/home/kurilovichay/.rvm/gems/ruby-2.3.1@global', execute `gem env` for more information
    from /usr/lib/ruby/2.3.0/rubygems/dependency.rb:328:in `to_spec'
    from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_gem.rb:65:in `gem'
    from /usr/local/bin/rubocop:22:in `<main>'
    at parseFromStd (/home/kurilovichay/.atom/packages/linter-rubocop/src/index.js:41:43)
    at Object.<anonymous> (/home/kurilovichay/.atom/packages/linter-rubocop/src/index.js:212:27)
    at next (<anonymous>)
    at step (/home/kurilovichay/.atom/packages/linter-rubocop/src/index.js:11:273)

which rubocop returns:

/usr/local/bin/rubocop

can someone assist with that?

Alvie answered 18/4, 2017 at 18:0 Comment(3)
Did you add the gem rubocop in your application?Achates
i just did this gem install rubocopAlvie
Sounds like a botched install.Doctorate
R
8

It seems that you're using rvm to manage your environment. What i did to get it to work was follow the instructions on their repo: https://github.com/AtomLinter/linter-rubocop#settings

# make sure I'm in the global gemset
$ rvm gemset use global
# install the gem
$ gem install rubocop

configure atom to use the global. Edit your atom's config file (config.cson) and add

*:
  "linter-rubocop":
    executablePath: "~/.rvm/gems/ruby-2.3.1@global/wrappers"
  "linter-ui-default": {}

Note: make sure that the ruby version is the one you're using.

Reel answered 30/6, 2017 at 11:3 Comment(3)
@Reel The problem with this solution is that you're locked into the Ruby version. Is there a solution that would allow any rvm ruby versions to use the same rubocop binary? That way, you don't ever need to set a specific path in the linter. It seems that the default path that the linter looks in is /usr/local/bin/rubocop? Perhaps installing it there somehow or syslink?Counterweight
@Counterweight you are entirely right when it comes to the being locked. That was a fix I did on my configuration at the time, but I have since stopped using Atom, so I haven't played around with it anymore. My opinion is that the rubocop lint should pick up whichever gemset is loaded in the path its being executed and if none, default to the default gemset. Not sure what is the current status, but it might worth for you to try to install rubocop globally (pennyforyourcode.com/…) and remove the executable path that i mention in my comment.Reel
Thanks for the link to that blog about the @global option. Unfortunately, my earlier comment was made in full knowledge of this option. The global option for example, you can have gemsets for ruby-2.5.1=> (default) global and gemsets for ruby-2.6.3=> (default) global. Each ruby version has its own set of gemsets and the global will install it within each version and be available for any of the gemsets that you create within each ruby version. Does that make sense? That means we still need to change the path on the linter each time we switch ruby versions.Counterweight
C
1

I had this same issue when working on a Rails 6 application in Ubuntu 20.04 with rbenv as my ruby version manager.

I already had rubocop installed in the project, but Atom editor was still throwing this error.

All I had to do was to install the rubocop gem to be available globally on the machine. Open a new terminal and install it using:

gem install rubocop

That's all.

I hope this helps

Cormophyte answered 14/10, 2020 at 9:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.