How to tell Rubocop to ignore a specific directory or file

前端 未结 4 1445
盖世英雄少女心
盖世英雄少女心 2020-12-29 00:34

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

相关标签:
4条回答
  • 2020-12-29 01: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

    0 讨论(0)
  • 2020-12-29 01:24

    From rubocop/default.yml:

    AllCops:
      Exclude:
        - 'node_modules/**/*'
        - 'vendor/**/*'
    
    0 讨论(0)
  • 2020-12-29 01:32

    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

    0 讨论(0)
  • 2020-12-29 01:34

    Can also consider comments for a single file. Great for ignoring the linter for a quick and dirty temporary task.

    # rubocop:disable all
    
    module TempTask
      ...
    end
    
    # rubocop:enable all
    
    0 讨论(0)
提交回复
热议问题