Antarr Byrd
Antarr Byrd

Reputation: 26159

Rubocop ignoring excludes specified in .rubocop.yml

I'm using Rubocop in CircleCI. And it's been configured to ignore the db folder. But it is still coming back with exceptions. I'm using a custom rake task in CI that is likely the cause. How can I modify it so that it ignores those excluded files/dirs?

rubocop.rake

# frozen_string_literal: true
namespace :rubocop do
  require 'rubocop/rake_task'

  desc 'Run RuboCop on entire project'
  RuboCop::RakeTask.new('all') do |task|
    task.fail_on_error = true
  end

  desc 'Run RuboCop on the project based on git diff(DIFF_BRANCH environment variable)'
  RuboCop::RakeTask.new('git_diff') do |task|
    task.patterns = patterns_for_changed_files
    task.fail_on_error = true
  end

  def changed_files
    diff_branch = ENV['DIFF_BRANCH'] || 'staging'
    cmd = %(git diff-tree -r --no-commit-id --diff-filter=M --name-only HEAD origin/#{diff_branch})
    diff = `#{cmd}`
    diff.split "\n"
    # diff.gsub!(/^(db\/|vendor\/|tmp\/|lib\/|test\/|bin\/)/, '').split "\n"
  end

  def patterns_for_changed_files
    patterns = []
    patterns + changed_files
  end
end

.rubocop.yml

AllCops:
  Exclude:
    - 'vendor/**/*'
    - 'tmp/**/*'
    - 'lib/**/*'
    - 'test/**/*'
    - 'bin/*'
    - 'config/**/*.yml'
    - 'db/**/*'
    - 'db/schema.rb'

Upvotes: 0

Views: 800

Answers (1)

Marcus Ilgner
Marcus Ilgner

Reputation: 7241

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.

Upvotes: 1

Related Questions