4

I would like to enable the Rubocop checker with Syntastic. I have set it has a checker and given the path to the executable. Although :SyntasticInfo reports that it is not an active checker. Also :SyntasticCheck rubocop reports that rubocop is not an available checker.

Are there any other settings I need? Could this be caused by the warning messages given by rubocop --version?


.vimrc settings

let g:syntastic_ruby_checkers          = ['rubocop', 'mri']
let g:syntastic_ruby_rubocop_exec      = '/Users/jjasonclark/.rbenv/shims/rubocop'

rubocop warning messages

warning: parser/current is loading parser/ruby21, which recognizes
warning: 2.1.5-compliant syntax, but you are running 2.1.2.
0.26.0

Edit: Based on comments I have discovered a partial workaround. The RBENV shim can be called with a command line parameter to specify the Ruby version. This works for running the command manually, but it doesn't work for the Syntastic plugin. My guess is it doesn't work because of the warning messages from Rubocop about the parser version.

let g:syntastic_ruby_rubocop_exec = 'RBENV_VERSION=2.1.2 /Users/jjasonclark/.rbenv/shims/rubocop'

Edit: I installed Ruby 2.1.5 and updated the RBENV_VERSION value to successfully remove the warning message. This still does not enable Rubocop for Syntastic. :SyntasticCheck rubocop still reports syntastic: warning: checker rubocop is not available

Jason
  • 3,736
  • 5
  • 33
  • 40

1 Answers1

1

Syntastic is loading the wrong version of Ruby. From your command line, enter ruby -v && which ruby.

Now, change the second line of the settings to:

let g:syntastic_ruby_rubocop_exec      = '/Users/jjasonclark/.rbenv/shims/ruby /Users/jjasonclark/yourprojectname/bin/rubocop'

Using whatever paths which ruby and which rubocop show you.

Dan Kohn
  • 33,811
  • 9
  • 84
  • 100
  • This sounds like the solution, but we are not quite there yet. Passing the rubocop path to the ruby shim doesn't work. It attempts to run it as a ruby script. – Jason Nov 25 '14 at 18:24
  • It does work if I set the full path to my project. Can you think of a way to make this generic enough to not only work with a single project? – Jason Nov 25 '14 at 23:34
  • 1
    You can install rubocop globally with `gem install rubocop` and it should then be available at `/Users/jjasonclark/.rbenv/shims/rubocop` – Dan Kohn Nov 26 '14 at 00:10
  • 1
    Tried that first. Installing globally causes the ruby version to change and thus create a warning message on `--version` calls. If there are any warnings then then Rubocop isn't available as a checker. – Jason Nov 26 '14 at 00:16
  • I'd want my current ruby to determine which ruby executable to use... something like `let g:syntastic_ruby_mri_exec = system("rbenv which ruby")` – rthbound Dec 30 '16 at 23:29