linter-rubocop icon indicating copy to clipboard operation
linter-rubocop copied to clipboard

Run rubocop with different ruby version

Open carlosbaraza opened this issue 10 years ago • 10 comments
trafficstars

Hi,

In my particular case, at work we are maintaining a big rails application developed in Ruby 1.8.7. However, we want to follow the recommendations from Rubocop (which does not support 1.8.7, but 1.9.3). We have some rules configured for our 1.8.7 version.

The problem is that in atom I was receiving this issue message (Obtained from the Linter debug option):

stderr /Users/baraza/.rvm/rubies/ree-1.8.7-2012.02/lib/ruby/site_ruby/1.8/rubygems.rb:900:in `report_activate_error': Could not find RubyGem rubocop (>= 0) (Gem::LoadError)
    from /Users/baraza/.rvm/rubies/ree-1.8.7-2012.02/lib/ruby/site_ruby/1.8/rubygems.rb:248:in `activate'
    from /Users/baraza/.rvm/rubies/ree-1.8.7-2012.02/lib/ruby/site_ruby/1.8/rubygems.rb:1276:in `gem'
    from /Users/baraza/.rvm/gems/ruby-1.9.3-p551/bin/rubocop:22
    from /Users/baraza/.rvm/gems/ree-1.8.7-2012.02/bin/ruby_executable_hooks:15

Then I decided to set the command (cmd) to execute directly on the linter-rubocop.coffee file. And also, not set up the rubocopExecutablePath config option.

cmd: '/Users/baraza/.rvm/rubies/ruby-1.9.3-p551/bin/ruby /Users/baraza/.rvm/gems/ruby-1.9.3-p551/bin/rubocop --format emacs'

However, this will bring another problem. The GEM_PATH environmental variable is not set:

stderr /Users/baraza/.rvm/rubies/ruby-1.9.3-p551/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:315:in `to_specs': Could not find 'rubocop' (>= 0) among 151 total gem(s) (Gem::LoadError)
Checked in 'GEM_PATH=/Users/baraza/.rvm/gems/ree-1.8.7-2012.02:/Users/baraza/.rvm/gems/ree-1.8.7-2012.02@global', execute `gem env` for more information
    from /Users/baraza/.rvm/rubies/ruby-1.9.3-p551/lib/ruby/site_ruby/1.9.1/rubygems/dependency.rb:324:in `to_spec'
    from /Users/baraza/.rvm/rubies/ruby-1.9.3-p551/lib/ruby/site_ruby/1.9.1/rubygems/core_ext/kernel_gem.rb:64:in `gem'
    from /Users/baraza/.rvm/gems/ruby-1.9.3-p551/bin/rubocop:22:in `<main>'

Finally, I solved this issue in the init.coffee adding this line to the activate function.

  activate: ->
    console.log 'activate linter-rubocop'
    process.env['GEM_PATH'] = ['/Users/baraza/.rvm/gems/ruby-1.9.3-p551', process.env['GEM_PATH']].join(':')

Now, I would like to maybe create a fork and solve this issue in a more elegant way. Does anybody has a recommendation on how to proceed with this? I thought about creating an optional config variable for the GEM_PATH, Ruby and Rubocop.

Thank you all for this great plugin. Carlos.

carlosbaraza avatar Dec 15 '14 17:12 carlosbaraza

GEM_PATH is wrongly set for me too, would be a nice feature!

thibaudgg avatar Aug 12 '15 09:08 thibaudgg

Pointing from the executable path to a small script using rvm underneath did the trick for me ;)

I mean something like this (with your ruby version of choice)

dcarral avatar Aug 20 '15 14:08 dcarral

FWIW I installed rubocop and reek on 1.9.3 like this:

gem install rubocop -v 0.41.2
gem install unparser -v 0.2.4
gem install reek -v 2.2.1

That doesn't help on 1.8.7 of course... Just figured I'd mention it here so I'll find it when I'm googling for this two years from now.

bronson avatar Oct 07 '16 19:10 bronson

Has anyone found a fix for this?

chrishough avatar Dec 31 '16 23:12 chrishough

@chrishough I have created new file .atom/rubocop with chmod +x:

#!/bin/bash
source ~/.rvm/scripts/rvm
rvm use --your_ruby_version--@--your_gemset(if you use)-- &>/dev/null
rubocop $@

Don't forget to replace your_ruby_version and your_gemset. If you don't use gemset, just use rvm use --your_ruby_version-- &>/dev/null

quolpr avatar Nov 20 '17 17:11 quolpr

rvm-exec bundle exec rubocop worked for me

ngan avatar May 02 '18 17:05 ngan

We are using rbenv @quolpr @ngan, thoughts?

chrishough avatar May 02 '18 18:05 chrishough

Looks like rbenv has their own exec: https://github.com/rbenv/rbenv/blob/master/libexec/rbenv-exec

ngan avatar May 02 '18 18:05 ngan

Thank you @ngan

chrishough avatar May 02 '18 19:05 chrishough

This will be implemented on #411

vzamanillo avatar Apr 28 '20 19:04 vzamanillo