Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell Rubocop to ignore a specific directory or file

Tags:

ruby

rubocop

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?

like image 263
emery Avatar asked Apr 27 '16 17:04

emery


People also ask

How do I ignore a RuboCop file?

By adding the option --exclude-limit COUNT , e.g., rubocop --auto-gen-config --exclude-limit 5 , you can change how many files are excluded before the cop is entirely disabled.

How do you customize RuboCop?

Just create . rubocop. yml file in either in your home directory or in some project directory and override settings you want.

What is RuboCop todo?

RuboCop's TODO file is generated by the command line option auto-gen-config : rubocop --auto-gen-config. This action runs rubocop across your entire code base, then constructs a set of rule exceptions that effectively 'ignore' code that doesn't fit into the existing guidelines.

Where is RuboCop located?

The RuboCop behavior can be controlled in the . rubocop. yml file in the root path where you want to execute it. In this file, you can enable/disable certain cops (rules) or change their behavior.


3 Answers

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

like image 165
emery Avatar answered Oct 11 '22 19:10

emery


From rubocop/default.yml:

AllCops:
  Exclude:
    - 'node_modules/**/*'
    - 'vendor/**/*'
like image 55
Dorian Avatar answered Oct 11 '22 20:10

Dorian


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
like image 25
Dennis Avatar answered Oct 11 '22 20:10

Dennis