Skip to content

Instantly share code, notes, and snippets.

@monkseal
Created April 22, 2015 15:36
Show Gist options
  • Select an option

  • Save monkseal/6d7f3b390c2d6c780dec to your computer and use it in GitHub Desktop.

Select an option

Save monkseal/6d7f3b390c2d6c780dec to your computer and use it in GitHub Desktop.
namespace :ci do
require 'rubocop/rake_task'
def changed_files
cmd = %q( git diff --name-only --diff-filter=ACMRTUXB \
$(git merge-base HEAD master) \
| egrep '\.rake$|\.rb$' )
diff = `#{cmd}`
diff.split("\n")
end
def patterns_for_changed_files
# always include the ci.rake file, if the patterns is empty it runs everything
patterns = ['lib/tasks/ci.rake']
patterns += changed_files
end
desc 'Run RuboCop on the entire project'
RuboCop::RakeTask.new('rubocop') do |task|
task.fail_on_error = true
end
desc 'Run RuboCop on the project based on git diff'
RuboCop::RakeTask.new('rubocop_changed') do |task|
task.patterns = patterns_for_changed_files
task.fail_on_error = true
end
end
@RomainFranklin
Copy link

very useful thx !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment