When rubocop -R is run, it takes into account the db/schema.rb file, which as you know is generated automatically when a migration is done so nothing can be done about its offences. Am I right?
A simple workaround is to create a .rubocop.yml file in the root of your Rails project with the following contents:
AllCops:
Excludes:
- db/schema.rb
I have the following in my Rails project:
AllCops:
Excludes:
- config/unicorn.rb
- db/**
RunRailsCops: true
Ahh, I see. Never mind then. Thanks.
:+1:
Possible bug for me?
RuboCop version 0.52.0.
ruby 2.4.0
Rails 5.1.3
I updated to Exclude as @dorian suggested, it still fails. I've also run it both with & without quotes.

What's interesting is when I run rubocop from the command line it passes, however I have a git hook on my commits and that's when it complains.

@PrimeTimeTran Can you show me the command line that you executed?
If you specify db/schema.rb with command line, rubocop does not ignore it.
% cat .rubocop.yml| head
require: 'rubocop-rspec'
AllCops:
Exclude:
- 'vendor/**/*'
- 'db/schema.rb'
DisplayCopNames: true
TargetRubyVersion: 2.4
Layout/AlignArray:
% rubocop | grep 'db/schema.rb' # nothing displayed
% rubocop db/schema.rb | grep 'db/schema.rb'
db/schema.rb:13:1: C: Metrics/BlockLength: Block has too many lines. [496/30]
db/schema.rb:24:13: C: Style/WordArray: Use %w or %W for an array of words.
db/schema.rb:26:13: C: Style/WordArray: Use %w or %W for an array of words.
db/schema.rb:48:13: C: Style/WordArray: Use %w or %W for an array of words.
db/schema.rb:88:13: C: Style/WordArray: Use %w or %W for an array of words.
db/schema.rb:102:13: C: Style/WordArray: Use %w or %W for an array of words.
db/schema.rb:215:13: C: Style/WordArray: Use %w or %W for an array of words.
db/schema.rb:272:13: C: Style/WordArray: Use %w or %W for an array of words.
db/schema.rb:340:13: C: Style/WordArray: Use %w or %W for an array of words.
db/schema.rb:353:13: C: Style/WordArray: Use %w or %W for an array of words.
db/schema.rb:397:13: C: Style/WordArray: Use %w or %W for an array of words.
db/schema.rb:406:13: C: Style/WordArray: Use %w or %W for an array of words.
db/schema.rb:481:13: C: Style/WordArray: Use %w or %W for an array of words.
See also https://github.com/bbatsov/rubocop/issues/5139#issuecomment-348678866
@pocke it's a git hook =). What can I show you in the hook that could be useful? Sorry, I'm not super familiar with linux so I'm not sure what all this does.
if command -v rubocop > /dev/null; then
git status --porcelain \
| grep -E '^A|^M' \
| grep '.rb' \
| awk '{print $2}' \
| xargs rubocop
fi
When I ran cat .rubocop.yml| head I got this.
```
➜ railsbuuk git:(master) ✗ cat .rubocop.yml| head
inherit_from: .rubocop_todo.yml
AllCops:
TargetRubyVersion: 2.4.0
DisplayCopNames: true
Exclude:
- 'app/assets/stylesheets/application.scss'
- 'config/routes.rb'
- 'db//.rb'
- 'node_modules//'
It looks executing rubocop with changed files.
Can you try updating your script with the following? It adds --force-exclusion option to avoid this problem.
if command -v rubocop > /dev/null; then
git status --porcelain \
| grep -E '^A|^M' \
| grep '.rb' \
| awk '{print $2}' \
| xargs rubocop --force-exclusion
fi
@pocke that resolved it. Thanks for the help!
Most helpful comment
A simple workaround is to create a
.rubocop.ymlfile in the root of your Rails project with the following contents:I have the following in my Rails project: