How to tell Rubocop to ignore a specific directory

2019-02-07 16:02发布

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?

标签: ruby rubocop
3条回答
Fickle 薄情
2楼-- · 2019-02-07 16:17

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

查看更多
叛逆
3楼-- · 2019-02-07 16:21

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

See formal explanation of .rubocop.yml here.

AllCops:
  Excludes:
    - 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

查看更多
我命由我不由天
4楼-- · 2019-02-07 16:21

From rubocop/default.yml:

AllCops:
  Exclude:
    - 'node_modules/**/*'
    - 'vendor/**/*'
查看更多
登录 后发表回答