How to tell Rubocop to ignore a specific directory or file

冷暖自知 提交于 2019-11-30 13:34:30

问题


My project is extending open-source classes from a third-party gem that we don't want to hold to the same coding standards as our own code. Refactoring the gem code isn't a viable option. We just want Rubocop to ignore the copied code.

How can I instruct Rubocop to completely ignore a file or directory?


回答1:


As per orde's comment with the link to the manual I found .rubocop.yml and added the following:

AllCops:
  Exclude:
    - 'path/to/excluded/file.rb'

where the path is relative to .rubocop.yml




回答2:


From rubocop/default.yml:

AllCops:
  Exclude:
    - 'node_modules/**/*'
    - 'vendor/**/*'



回答3:


For your convenience, here is the .rubocop.yml I frequently used.

See formal explanation of .rubocop.yml here.

AllCops:
  Exclude:
    - Berksfile
    - recipes/basic.rb
    - attributes/*.rb

# Customize rules
Metrics/LineLength:
  Max: 95

MethodLength:
  Max: 35

Metrics/AbcSize:
   Enabled: false

BlockLength:
  Max: 70

I constantly bump by rubocop errors and warning. Thus I've published this post.

Common Rubocop Errors: Improve Your Ruby Code Quality



来源:https://stackoverflow.com/questions/36896279/how-to-tell-rubocop-to-ignore-a-specific-directory-or-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!