I have the following in my project's .rubocop.yml:
AllCops:
TargetRubyVersion: 2.4.1
Include:
- '**/Rakefile'
- '**/config.ru'
Exclude:
- 'db/**/*'
- 'config/**/*'
- 'script/**/*'
- 'cache/**/*'
- 'bin/*'
- 'node_modules/**/*'
This used to scan every .rb file in the project, except those specified under Exclude, plus any Rakefile or config.ru.
After updating Rubocop to the version below, the Include section now seems to discard the default and only scan the files listed in that section.
Adding - '**/*.rb' to the Include section works around this, but previous versions did not require this. I'd argue that it makes more sense Include and Exclude to just add to or subtract from the default — maybe have an EmptyDefaultIncludeList: true option (defaults to false) for those who want the new behaviour?
It looks like commit 628ab0f69 might be related to this.
└─▷ rubocop -L
config.ru
Rakefile
app/controllers/admin/users_controller.rb
app/controllers/application_controller.rb
app/controllers/events_controller.rb
app/controllers/home_controller.rb
app/controllers/pages_controller.rb
app/decorators/admin/user_decorator.rb
app/decorators/application_decorator.rb
app/decorators/event_decorator.rb
app/decorators/events_decorator.rb
app/decorators/page_decorator.rb
app/helpers/admin/users_helper.rb
app/helpers/application_helper.rb
app/helpers/devise_helper.rb
app/helpers/events_helper.rb
app/helpers/home_helper.rb
app/helpers/pages_helper.rb
app/jobs/application_job.rb
app/mailers/application_mailer.rb
app/models/application_record.rb
app/models/calendar_feed.rb
app/models/event.rb
app/models/page.rb
app/models/user.rb
app/policies/application_policy.rb
app/policies/page_policy.rb
app/policies/user_policy.rb
spec/controllers/events_controller_spec.rb
spec/controllers/pages_controller_spec.rb
spec/decorators/event_decorator_spec.rb
spec/decorators/events_decorator_spec.rb
spec/decorators/page_decorator_spec.rb
spec/factories/calendar_feeds.rb
spec/factories/events.rb
spec/factories/pages.rb
spec/factories/users.rb
spec/helpers/events_helper_spec.rb
spec/helpers/pages_helper_spec.rb
spec/models/calendar_feed_spec.rb
spec/models/event_spec.rb
spec/models/page_spec.rb
spec/models/user_spec.rb
spec/policies/page_policy_spec.rb
spec/policies/user_policy_spec.rb
spec/rails_helper.rb
spec/spec_helper.rb
spec/support/custom_selectors.rb
spec/support/devise.rb
spec/support/factory_bot.rb
spec/support/geocoder.rb
spec/support/pundit.rb
spec/support/system_tests.rb
spec/system/logins_spec.rb
spec/system/pages_spec.rb
└─▷ rubocop -L
config.ru
Rakefile
Create a project with an Include section under AllCops that does not specifically include Ruby files and run rubocop -L.
└─▷ rubocop -V
0.56.0 (using Parser 2.5.1.0, running on ruby 2.4.4 x86_64-darwin16)
The documentation indicates that this behavior is intentional.
Files that match any pattern listed under AllCops/Include and extensionless files with a hash-bang (#!) declaration containing one of the known ruby interpreters listed under AllCops/RubyInterpreters are inspected, unless the file also matches a pattern in AllCops/Exclude.
http://docs.rubocop.org/en/latest/configuration/#includingexcluding-files
Happily, in your case, you can remove the Include section. Both Rakefile and config.ru will be included. Tested in rubocop 0.58.1.
Happily, in your case, you can remove the Include section. Both Rakefile and config.ru will be included. Tested in rubocop 0.58.1.
They are included because they are explicitly listed in default.yml
AllCops:
Include:
- '**/*.rb'
...
- '**/*.ru'
...
- '**/Rakefile'
By removing your Include, you can choose to use the one from default.yml.
This is not the behavior it used to have. Formerly, it would merge inclusion lists from default.yml with additional ones specified in .rubocop.yml. Currently, inclusion in .rubocopy.yml overrides all inclusions in default.yml.
This is undesirable behavior, as having the default inclusions plus more requires copying default's entire inclusion list into .rubocop.yml.
This is undesirable behavior, as having the default inclusions plus more requires copying default's entire inclusion list into .rubocop.yml.
Makes sense. I'm not sure why they made that change. Have you done any poking around, perhaps with git blame, to find out why the behavior changed?
Ah, if only someone ever read the changelog or the manual...
I've made this decision explicitly, it's not a mistake and the old behavior is never coming back.
For the rationale:
For the proper way to merge your additions with the defaults read http://docs.rubocop.org/en/latest/configuration/#includingexcluding-files
Thanks for the links Bozhidar. John, from my reading of https://github.com/rubocop-hq/rubocop/pull/5847 it sounds like if you use AllCops/Include you must copy over whatever you need from default.yml.
I think the docs on this could be improved. The only relevant line I see is:
If you'd like RuboCop to check files that are not included by default, you'll need to pass them in on the command line, or to add entries for them under AllCops/Include.
http://docs.rubocop.org/en/latest/configuration/#includingexcluding-files
I'll take a stab at improving that docs page.
My attempt at better docs: https://github.com/rubocop-hq/rubocop/pull/6134
Most helpful comment
This is not the behavior it used to have. Formerly, it would merge inclusion lists from default.yml with additional ones specified in .rubocop.yml. Currently, inclusion in .rubocopy.yml overrides all inclusions in default.yml.
This is undesirable behavior, as having the default inclusions plus more requires copying default's entire inclusion list into .rubocop.yml.