Created
April 22, 2015 15:36
-
-
Save monkseal/6d7f3b390c2d6c780dec to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
very useful thx !