Making SublimeLinter work with rbenv and rubocop

by

After installing [SublimeLinter 3](http://www.sublimelinter.com/en/latest/) and [SublimeLinter-rubocop](https://github.com/SublimeLinter/SublimeLinter-rubocop) in Sublime Text 3, I saw the following error in the Sublime Text 3 console (which you can pull up with ctrl + `):

`SublimeLinter: rubocop version query: /Users/samh/.rbenv/shims/ruby -S rubocop –version` `SublimeLinter: WARNING: no rubocop version could be extracted from:` `ruby: no Ruby script found in input (LoadError)`

This is a pretty gnarly error, since there are a lot of moving pieces:

1. [Sublime Text 3](http://www.sublimetext.com/3): the text editor. 2. [SublimeLinter 3](http://www.sublimelinter.com/en/latest/): a linting framework for Sublime Text 3. 3. [SublimeLinter-rubocop](https://github.com/SublimeLinter/SublimeLinter-rubocop): a SublimeLinter 3 _plugin_ that helps rubocop hook into the SublimeLinter framework. 4. [rubocop](https://github.com/bbatsov/rubocop): a “Ruby static code analyzer” that does the actual checking of your source code. 5. [rbenv](https://github.com/sstephenson/rbenv): a Ruby environment manager, which helps you have multiple Ruby versions on your system.

To address the error, begin by making sure that your `SublimeLinter.sublime-settings` file has your [`~/.rbenv/shims` directory in its “paths” hash](http://sublimelinter.readthedocs.org/en/latest/troubleshooting.html#debugging-path-problems) (run `which ruby` to get an idea of where your rbenv shims path is). This makes sure that SublimeLinter has your rbenv stuff in its path. Your “paths” hash should look something like this:

“` “paths”: { “linux”: [], “osx”: [ “~/.rbenv/shims” ], “windows”: [] }, “`

If the `no Ruby script found in input` error persists, the next step is to add a default Ruby to your rbenv installation. You can either manually edit a file at `~/.rbenv/version` or run `rbenv global 2.1.2`. This will set a base Ruby version for rbenv to use systemwide, unless it’s overridden. You don’t need to use 2.1.2 — you just need any rubocop-compatible Ruby version.

After setting a default global Ruby, navigate to any directory without a `.ruby-version` file (try `cd ~`) and run `ruby -v` to make sure that the active Ruby version matches the one you just set as default. Then, run `gem install rubocop` so that that default Ruby environment has the rubocop gem. Finally, run `rbenv rehash`.

At this point, you should have a default rbenv Ruby with its own associated environment that contains rubocop. Furthermore, SublimeLinter should know about the directory that contains this Ruby setup.

Now, exit Sublime Text 3 and reopen the program. Navigate to a Ruby file, and you should see SublimeLinter-rubocop doing its thing! If you open the Sublime Text console, you should see some actual rubocop output, too.

** Note: you may need to re-activate the rubocop linter in your SublimeLinter settings file by setting rubocop’s `@disabled` attribute to `false`.**

In review: Providing a systemwide default rbenv Ruby version — and installing rubocop to that Ruby version — lets SublimeLinter-rubocop run the programs it needs to lint your Ruby files.

If you run into any trouble, let me know in the comments.