简体   繁体   中英

Rubocop and Style/IndentationConsistency with rails enabled

I am using rubocop to a rails 5 project and I've added to my .rubocop.yml this:

Rails:
  Enabled: true

I noticed however that a rule ( Style/IndentationConsistency ) was failing and I had to explicitly add it like this:

Style/IndentationConsistency:
  EnforcedStyle: rails

Is it ok to happen or am I doing something wrong?

You can't just add Rails: Enabled: true, you will need to add the Rails individual configurations like (Rails Action Filter, FindEach, FindBy).

Please refer Rails configurations as given below. You can also this this 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

Seems that this is ok to happen. Not everyone is using this style in Rails projects. It's just the style used the Rails codebase itself. So if you need the rails codebase indentation you have to explicitly put both of the above.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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