简体   繁体   English

如何使用Syntastic Vim插件和Rbenv启用Rubocop?

[英]How to enable Rubocop with Syntastic Vim plugin and Rbenv?

I would like to enable the Rubocop checker with Syntastic. 我想启用Syntastic的Rubocop检查器。 I have set it has a checker and given the path to the executable. 我已经设置了它具有检查器,并给出了可执行文件的路径。 Although :SyntasticInfo reports that it is not an active checker. 尽管:SyntasticInfo报告它不是活动的检查器。 Also :SyntasticCheck rubocop reports that rubocop is not an available checker. 另外:SyntasticCheck rubocop报告说rubocop不是可用的检查器。

Are there any other settings I need? 我还需要其他设置吗? Could this be caused by the warning messages given by rubocop --version ? 这可能是由rubocop --version给出的警告消息引起的吗?


.vimrc settings .vimrc设置

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

rubocop warning messages rubocop警告消息

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. 可以使用命令行参数来调用RBENV垫片,以指定Ruby版本。 This works for running the command manually, but it doesn't work for the Syntastic plugin. 这适用于手动运行命令,但不适用于Syntastic插件。 My guess is it doesn't work because of the warning messages from Rubocop about the parser version. 我的猜测是它不起作用,因为来自Rubocop的关于解析器版本的警告消息。

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. 编辑:我安装了Ruby 2.1.5,并更新了RBENV_VERSION值以成功删除警告消息。 This still does not enable Rubocop for Syntastic. 这仍然不能启用Rubocop for Syntastic。 :SyntasticCheck rubocop still reports syntastic: warning: checker rubocop is not available :SyntasticCheck rubocop仍报告syntastic: warning: checker rubocop is not available

Syntastic is loading the wrong version of Ruby. Syntastic正在加载错误版本的Ruby。 From your command line, enter ruby -v && which ruby . 在命令行中,输入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. 使用which ruby路径显示which rubywhich rubocop

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM