简体   繁体   English

Rubocop:错误 - rubocop 返回退出代码 2

[英]Rubocop: Error - rubocop returned exit code 2

I just cloned a Ruby on Rails project to my local machine to work on it.我刚刚将一个 Ruby on Rails 项目克隆到我的本地计算机上进行处理。 I have ran the command bundle install in order to install all the necessary gems and dependencies required for the project.我已经运行了命令bundle install以安装项目所需的所有必要的 gem 和依赖项。

But a message keeps popping up in my log messages, which gets me worried.但是我的日志消息中不断弹出一条消息,这让我很担心。 It is这是

Error:Rubocop returned exit code: 2错误:Rubocop 返回退出代码:2

I have checked the version of rubocop that I have installed and it seems to be up-to-date.我检查了我安装的rubocop版本,它似乎是最新的。 I have also done some research as to what might be the cause of this error, but I seem not to have any luck yet.我还对可能导致此错误的原因进行了一些研究,但我似乎还没有运气。 I need some assistance.我需要一些帮助。

According to RuboCop HQ commit message in relation to this issue ( Return exit code 2 if RuboCop fails due to internal error ), it was stated that " RuboCop returns process exit code 2 if it fails due to bad configuration, bad CLI options, or an internal error. If it runs successfully but finds one or more offenses, it still exits with code 1, as was previously the case. This is helpful when invoking RuboCop programmatically, perhaps from a script. "根据与此问题相关的 RuboCop HQ 提交消息(如果 RuboCop 由于内部错误而失败,则返回退出代码 2 ),指出“如果由于错误的配置、错误的 CLI 选项或错误而失败,RuboCop 返回进程退出代码 2 “

After a more thorough review of my application, I checked the log message and realized that I was also having an error below the Error:Rubocop returned exit code: 2 , which is cannot load such file -- rubocop-performance .在对我的应用程序进行了更彻底的审查后,我检查了日志消息,并意识到我在Error:Rubocop returned exit code: 2下面也有一个错误,即cannot load such file -- rubocop-performance

So I quickly checked my Gemfile and realized that some gems listed in my Gemfile that have rubocop as a runtime dependency have not been installed.所以我迅速检查了我的Gemfile ,并意识到我的Gemfile中列出的一些将rubocop作为运行时依赖项的 gem 尚未安装。

The full list of the gems are宝石的完整列表是

gem 'rubocop-performance'
gem 'rubocop-rails'
gem 'rubocop-rspec'

All I had to do was to simply install the gems individually via my terminal我所要做的就是通过我的终端单独安装 gems

gem install rubocop-performance
gem install rubocop-rails
gem install rubocop-rspec

And that fixed the issue for me.这为我解决了这个问题。

That's all.就这样。

I hope this helps我希望这有帮助

I also face a similar problem with my VS code format.我的 VS 代码格式也面临类似的问题。 It was resolved after doing a bundle install from the vscode terminal.从 vscode 终端进行bundle install后,它已解决。

Looks like the root cause was some of the gem dependencies of rubocop were not installed to the default gemset and were available only in my project gemset.看起来根本原因是 rubocop 的一些 gem 依赖项没有安装到默认 gemset 中,并且仅在我的项目 gemset 中可用。

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

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