启用了rails的Rubocop和Style / IndentationConsistency

时间:2016-08-23 07:39:27

标签: ruby-on-rails ruby rubocop

我正在使用rubocop进行rails 5项目,并且我已添加到.rubocop.yml这个:

Rails:
  Enabled: true

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

Style/IndentationConsistency:
  EnforcedStyle: rails

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

2 个答案:

答案 0 :(得分:0)

您不能只添加Rails:Enabled:true,您需要添加Rails个别配置,如(Rails Action Filter,FindEach,FindBy)。

请参考下面给出的Rails配置。 您也可以通过此链接(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

答案 1 :(得分:0)

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