Skip to content
This repository has been archived by the owner on Aug 7, 2023. It is now read-only.

Run rubocop with different ruby version #21

Open
carlosbaraza opened this issue Dec 15, 2014 · 10 comments
Open

Run rubocop with different ruby version #21

carlosbaraza opened this issue Dec 15, 2014 · 10 comments

Comments

@carlosbaraza
Copy link
Contributor

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.

@thibaudgg
Copy link

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

@dcarral
Copy link

dcarral commented Aug 20, 2015

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)

@bronson
Copy link

bronson commented Oct 7, 2016

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.

@chrishough
Copy link

Has anyone found a fix for this?

@quolpr
Copy link

quolpr commented Nov 20, 2017

@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

@ngan
Copy link

ngan commented May 2, 2018

rvm-exec bundle exec rubocop worked for me

@chrishough
Copy link

We are using rbenv @quolpr @ngan, thoughts?

@ngan
Copy link

ngan commented May 2, 2018

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

@chrishough
Copy link

Thank you @ngan

@vzamanillo
Copy link
Contributor

This will be implemented on #411

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

9 participants