Rubocop 和 Style/IndentationConsistency 启用了 rails

Rubocop and Style/IndentationConsistency with rails enabled

我正在将 rubocop 用于 rails 5 项目,并且我已将此添加到我的 .rubocop.yml 中:

Rails:
  Enabled: true

但是我注意到规则 (Style/IndentationConsistency) 失败了,我不得不像这样明确地添加它:

Style/IndentationConsistency:
  EnforcedStyle: rails

可以发生还是我做错了什么?

您不能只添加 Rails: Enabled: true,您需要添加 Rails 单独的配置,例如 (Rails Action Filter、FindEach、FindBy)。

请参考下面给出的Rails配置。 你也可以这样 link(https://github.com/bbatsov/rubocop/blob/master/config/default.yml)

  Rails/ActionFilter:
      EnforcedStyle: action
      SupportedStyles:
          - action
          - filter
      Include:
          - app/controllers/**/*.rb

  Rails/Date:
      # The value `strict` disallows usage of `Date.today`, `Date.current`,
      # `Date#to_time` etc.
      # The value `flexible` allows usage of `Date.current`, `Date.yesterday`, etc
      # (but not `Date.today`) which are overridden by ActiveSupport to handle current
      # time zone.
      EnforcedStyle: flexible
      SupportedStyles:
          - strict
          - flexible

  Rails/Exit:
      Include:
          - app/**/*.rb
          - config/**/*.rb
          - lib/**/*.rb
      Exclude:
          - lib/**/*.rake

  Rails/FindBy:
      Include:
          - app/models/**/*.rb

  Rails/FindEach:
      Include:
          - app/models/**/*.rb

  Rails/HasAndBelongsToMany:
      Include:
          - app/models/**/*.rb

这似乎是可以发生的。并不是每个人都在 Rails 个项目中使用这种风格。这只是使用 Rails 代码库本身的样式。因此,如果您需要 rails 代码库缩进,则必须显式放置以上两项。