How to Tell Rubocop to Ignore a Specific Directory or File

How to tell Rubocop to ignore a specific directory or file

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

Rubocop: how can I exclude a filename pattern from a metric?

You can match files based on a regular expression by using the !ruby/regexp declaration:

Metrics/LineLength:
Max: 80
AllowHeredoc: true
AllowURI: true
URISchemes:
- http
- https
Exclude:
- !ruby/regexp /_spec\.rb$/

RuboCop recently added a new manual, and you can read about including and excluding files here.

Rubocop ignoring excludes specified in .rubocop.yml

If you run Rubocop from a Rake task, this is expected behaviour. Also see this related issue on Github.

Personally I'd recommend running it from a shell script with command line arguments instead.
To achieve the check for changed files, you can use pronto in conjunction with pronto-rubocop.

RuboCop: Different parameters for different directories

Create separate .rubocop.yml in /spec with desired rules. Rubocop will pick it up

RuboCop will start looking for the configuration file in the directory
where the inspected file is and continue its way up to the root
directory.

Ref https://rubocop.readthedocs.io/en/latest/configuration/

How do I suppress Rubocop Conventions?

rubocop --only Syntax,Lint

From https://github.com/bbatsov/rubocop/issues/2337#issuecomment-150477553

If you don't have any custom severity levels in your configuration, it's quite simple. The Synax cop reports on fatal and error level, Lint cops on warning level and all other cops on convention level.

So for only fatal and error, it's rubocop --only Syntax (which is only supported on master, not released yet), and for warningand above it's rubocop --only Lint.



Related Topics



Leave a reply



Submit