VSCode/Rubocop 抱怨未配置的警察

aar*_*ona 7 ruby rubocop visual-studio-code

我最近更新rubocop了我正在研究的 gem。当我使用 VSCode 在项目中打开一个 ruby​​ 文件时,我收到以下警告:

The following cops were added to RuboCop, but are not configured. Please set Enabled to either `true` or `false` in your `.rubocop.yml` file:
 - Lint/RaiseException (0.81)
 - Lint/StructNewOverride (0.81)
 - Style/HashEachMethods (0.80)
 - Style/HashTransformKeys (0.80)
 - Style/HashTransformValues (0.80)
For more information: https://docs.rubocop.org/en/latest/versioning/
Run Code Online (Sandbox Code Playgroud)

这是我的.rubocop.yml文件:

The following cops were added to RuboCop, but are not configured. Please set Enabled to either `true` or `false` in your `.rubocop.yml` file:
 - Lint/RaiseException (0.81)
 - Lint/StructNewOverride (0.81)
 - Style/HashEachMethods (0.80)
 - Style/HashTransformKeys (0.80)
 - Style/HashTransformValues (0.80)
For more information: https://docs.rubocop.org/en/latest/versioning/
Run Code Online (Sandbox Code Playgroud)

当我访问警告中的url时,它提到添加如下NewCops设置:

Metrics/MethodLength:
  Max: 20
Layout/LineLength:
  Max: 100
AllCops:
  Exclude:
    - 'spec/**/*'
Run Code Online (Sandbox Code Playgroud)

但是,我收到了这个新警告:

Warning: AllCops does not support NewCops parameter.

Supported parameters are:

  - RubyInterpreters
  - Include
  - Exclude
  - DefaultFormatter
  - DisplayCopNames
  - DisplayStyleGuide
  - StyleGuideBaseURL
  - ExtraDetails
  - StyleGuideCopsOnly
  - EnabledByDefault
  - DisabledByDefault
  - UseCache
  - MaxFilesInCache
  - CacheRootDirectory
  - AllowSymlinksInCacheRootDirectory
  - TargetRubyVersion
The following cops were added to RuboCop, but are not configured. Please set Enabled to either `true` or `false` in your `.rubocop.yml` file:
 - Lint/RaiseException (0.81)
 - Lint/StructNewOverride (0.81)
 - Style/HashEachMethods (0.80)
 - Style/HashTransformKeys (0.80)
 - Style/HashTransformValues (0.80)
For more information: https://docs.rubocop.org/en/latest/versioning/
Run Code Online (Sandbox Code Playgroud)

警告指示我单独启用这些新警察中的每一个,但文档似乎有一个更简单的解决方案,但不起作用。我在这里做错了什么?

小智 7

如果您使用的是 VS 代码 ruby​​-rubocop 版本,这里有一个简单的修复程序 ->

配置扩展设置 -> 选择 Supress Rubocop Warnings ,如果您在存储库中共享 rubocop.yml 文件会很有帮助。

图片


小智 5

我在这里也有同样的问题。该NewCops参数中AllCops无法识别所以只有一个办法做到这一点是通过禁用或单独使每个警察像这样:

Lint/RaiseException:
  Enabled: false
Lint/StructNewOverride:
  Enabled: false
Style/HashEachMethods:
  Enabled: false
Style/HashTransformKeys:
  Enabled: false
Style/HashTransformValues:
  Enabled: false
Run Code Online (Sandbox Code Playgroud)

希望这是有帮助的。