简体   繁体   English

使用 rubocop 在 Emacs flycheck 模式下出错

[英]Error in Emacs flycheck mode with rubocop

I use flycheck mode with rubocop checker.我使用带有 rubocop 检查器的 flycheck 模式。

when I open some rb file,当我打开一些 rb 文件时,

Checker ruby-rubocop returned non-zero exit code 1, but no errors from output: /Users/abc/.rvm/rubies/ruby-2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/specification.rb:2157:in `method_missing': undefined method `this' for #<Gem::Specification:0x3fc38c8edb10 rubocop-0.35.1> (NoMethodError)
    from /Users/abc/.rvm/rubies/ruby-2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/specification.rb:1056:in `find_active_stub_by_path'
    from /Users/abc/.rvm/rubies/ruby-2.2.3/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:63:in `require'
    from /Users/abc/.rvm/gems/ruby-2.2.3/gems/rubocop-0.35.1/bin/rubocop:6:in `<top (required)>'
    from /Users/abc/.rvm/gems/ruby-2.2.3/bin/rubocop:23:in `load'
    from /Users/abc/.rvm/gems/ruby-2.2.3/bin/rubocop:23:in `<main>'
    from /Users/abc/.rvm/gems/ruby-2.2.3/bin/ruby_executable_hooks:15:in `eval'
    from /Users/abc/.rvm/gems/ruby-2.2.3/bin/ruby_executable_hooks:15:in `<main>'

Checker definition probably flawed.

And flycheck mode is not working而且飞行检查模式不起作用

I also use projectile / projectile-rails mode.我也使用射弹/射弹轨道模式。 But rb files of some projects are not raise errors.但是某些项目的 rb 文件不会引发错误。 Error is occured some project.某些项目发生错误。

Hard to tell you what is going on without seeing it run on the command line.如果没有看到它在命令行上运行,很难告诉你发生了什么。

I had the same error, and it turned out I was using an older version of Rubocop, and the FlyCheck was calling the rubocop executable with an option that it didn't understand ( --display-cop-names ).我遇到了同样的错误,结果我使用的是旧版本的 Rubocop,而 FlyCheck 正在调用rubocop可执行文件,并带有一个它不理解的选项( --display-cop-names )。

So run it from the command line, and post the results and then we can try to diagnose the problem.所以从命令行运行它,并发布结果,然后我们可以尝试诊断问题。

For what it's worth, I was seeing this:对于它的价值,我看到了这个:

/Users/alexmoore-niemi/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems/specification.rb:2158:in `method_missing': undefined method `this' for #<Gem::Specification:0x3fce0dc538dc rubocop-0.47.1> (NoMethodError)
    from /Users/alexmoore-niemi/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems/specification.rb:1057:in `find_active_stub_by_path'
    from /Users/alexmoore-niemi/.rvm/rubies/ruby-2.3.0/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:64:in `require'
    from /Users/alexmoore-niemi/.rvm/gems/ruby-2.3.0/gems/rubocop-0.47.1/bin/rubocop:6:in `<top (required)>'
    from /Users/alexmoore-niemi/.rvm/gems/ruby-2.3.0/bin/rubocop:23:in `load'
    from /Users/alexmoore-niemi/.rvm/gems/ruby-2.3.0/bin/rubocop:23:in `<main>'
    from /Users/alexmoore-niemi/.rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `eval'
    from /Users/alexmoore-niemi/.rvm/gems/ruby-2.3.0/bin/ruby_executable_hooks:15:in `<main>'

But this problem was only in one of my projects;但是这个问题只出现在我的一个项目中; rubocop executed fine in another project! rubocop在另一个项目中执行得很好!

So I uninstalled rubocop, ran gem update --system , then reinstalled it, and it worked again in both projects.所以我卸载了 rubocop,运行gem update --system ,然后重新安装它,它在两个项目中再次运行。

I don't know why but after:我不知道为什么,但之后:

$ rubocop --auto-gen-config

in my Rails APP_ROOT, all works fine now.在我的 Rails APP_ROOT 中,现在一切正常。

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

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