Skip to content

Instantly share code, notes, and snippets.

@hayduke19us
Created August 14, 2016 17:52
Show Gist options
  • Save hayduke19us/33ae0a2e705486eb27e65473678b0c0e to your computer and use it in GitHub Desktop.
Save hayduke19us/33ae0a2e705486eb27e65473678b0c0e to your computer and use it in GitHub Desktop.
begin
require 'rubocop/rake_task'
modified_files = `git diff --name-only`.split(" ").map(&:strip)
included_files = modified_files.select { |f| f =~ /.*.rb\z/ }
if included_files.any?
RuboCop::RakeTask.new do |t|
t.patterns = included_files
end
else
desc 'Rubocop has no modified files to check'
task :rubocop do
puts 'No modified files for robocop to check'
end
end
rescue LoadError
desc 'Rubocop rake task not available (rubocop not installed)'
task :rubocop do
abort 'Rubocop rake task is not available.'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment