警告:无法识别的警察Rails /

Bra*_*iac 6 ruby-on-rails rubocop visual-studio-code

我在Vs代码中遇到Rubocop问题。我得到错误

Warning: unrecognized cop Rails/ActionFilter found in /path/to/yml/with/cops
...
Warning: unrecognized cop Rails/Output found in
...
Warning: unrecognized cop Rails/UnknownEnv found in
...
# The list goes on...
Run Code Online (Sandbox Code Playgroud)

我跑:

Rubocop版本rubocop-0.76.0

VS-code Version: 1.39.2

ruby-rubocop extention in vs code: 0.8.1

macOS Catalina: 10.15 (Problem existed in earlier versions like mojave)


I find very little about this problem. Basically only thing I found was this. And I already have require rubocop-rspec in my rspec yml file so no success with the proposals from that thread.

What can I do to solve this? My co-workers will soon start to call me Mr. Lint-failure

Gen*_*nís 16

以防万一您.rubocop.yml像我一样从不同的项目中复制文件,在我的情况下,我只是忘记添加rubocop-rails gem,其中包括 Rails/ cops

像任何其他 gem 一样安装它,并在您的.rubocop.yml文件中要求它:

# Gemfile

gem 'rubocop', require: false
gem 'rubocop-rails', require: false

Run Code Online (Sandbox Code Playgroud)
$ bundle install
Run Code Online (Sandbox Code Playgroud)
# .rubocop.yml

require: rubocop-rails
Run Code Online (Sandbox Code Playgroud)
$ rubocop
Run Code Online (Sandbox Code Playgroud)

  • `require: rubocop-rails` 就是我所需要的。谢谢。 (3认同)

小智 5

似乎 rubocop 警告正在阻止 rubocop 完成。在您的 rubocop 版本中,应该有一个名为suppressRubocopWarningstry 检查的设置,如果您知道不需要处理警告。

您可以通过键入cmd+shift+p并键入 Open User Settings来执行此操作。您可以在那里搜索rubocop并选中suppressRubocopWarnings复选框,重新启动 VSCode,它应该可以工作了。

如果您使用的是没有花哨 UI 的旧版本 VSCode,您应该能够"ruby.rubocop.suppressRubocopWarnings": true,在您的用户设置 json 中添加。

如果您跨多个项目共享 rubocop.yml 文件,则收到此类警告似乎很常见。

来源:https : //github.com/misogi/vscode-ruby-rubocop/pull/97