Rubocop: Cannot use the --only option with custom cop settings to run only rubocop-rails

Created on 18 Dec 2020  路  2Comments  路  Source: rubocop-hq/rubocop

When attempting to run only certain department cops form rubocop-rails using the rubocop --only flag, I get following error:

Error: `Rails/*` has been extracted to the `rubocop-rails` gem.
(obsolete configuration found in .rubocop.yml, please update it)

Expected behavior

It should allow me to run Rails cops only with one of them being disabled but the rest of the department working.

Actual behavior

Fails

Steps to reproduce the problem

# Gemfile
source 'https://rubygems.org'

gem 'rubocop-rails'
# .rubocop.yml

AllCops:
  Exclude:
    - bin/**/*
    - db/schema.rb
    - .gemspec/**/*
    - .bundle/**/*
    - vendor/**/*
    - '**/dummy**/*'
    - !ruby/regexp /old_and_unused\.rb$/

Rails/NotNullColumn:
  Enabled: false
# Shell command I use to run it

bundle exec rubocop --only Rails -- require rubocop-rails

RuboCop version

Include the output of rubocop -V or bundle exec rubocop -V if using Bundler.
If you see extension cop versions (e.g. rubocop-performance, rubocop-rspec, and others)
output by rubocop -V, include them as well. Here's an example:

rubocop -V
1.6.1 (using Parser 2.7.2.0, rubocop-ast 1.3.0, running on ruby 2.7.1 x86_64-linux)
[test]$ rubocop -v
bug

All 2 comments

Thank you for your feedback. A workaround is to change require rubocop-rails from command line argument to .rubocop.yml config.

+require: rubocop-rails

 AllCops:
   Exclude:
     - bin/**/*
     - db/schema.rb
     - .gemspec/**/*
     - .bundle/**/*
     - vendor/**/*
     - '**/dummy**/*'
     - !ruby/regexp /old_and_unused\.rb$/

 Rails/NotNullColumn:
   Enabled: false

I'll transfer the issue to the core because it is related to https://github.com/rubocop-hq/rubocop/pull/9169.

I'm on this.

Was this page helpful?
0 / 5 - 0 ratings