Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can a rubocop check be disabled on certain paths only?

I'm using ActiveAdmin, where the DSL predisposes you to forming large blocks. Thus, rubocop says:

Block has too many lines

  • I want to warn when non-active-admin files have large blocks.
  • I want to ignore large blocks in ActiveAdmin.
  • I do not want to add a per-file ignore instructions, (docs):

    # rubocop:disable BlockLength 
    
  • Ignoring the whole directory won't work, since other things could be missed.

I might consider some config for ActiveAdmin that will globally affect all of its registries, but I'd ideally put the config in the rubocop dotfile.

like image 236
New Alexandria Avatar asked Sep 07 '25 10:09

New Alexandria


1 Answers

You can disable a single cop for a single directory or specific files. Say, in your example, you want to exclude ActiveAdmin files from being inspected by Metrics/BlockLength, and your files are located in app/admin, you add this to your .rubocop.yml:

Metrics/BlockLength:
  Exclude:
    - 'app/admin/**/*'

Note that this will override the default excludes (rake and spec files.) If you still want them excluded as well, you'll need to add them to your configuration:

Metrics/BlockLength:
  Exclude:
    - 'app/admin/**/*'
    - 'Rakefile'
    - '**/*.rake'
    - 'spec/**/*.rb'
like image 136
Drenmi Avatar answered Sep 11 '25 01:09

Drenmi