Skip to content

Instantly share code, notes, and snippets.

@reidab
Created April 11, 2018 23:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save reidab/de79978aaaba4fb16186589b30c0765d to your computer and use it in GitHub Desktop.
Save reidab/de79978aaaba4fb16186589b30c0765d to your computer and use it in GitHub Desktop.
# frozen_string_literal: true
# Code Metrics
#-------------------------------------------------------------------------------
namespace :metrics do
task :init_status do
@metrics_exit ||= 0
end
desc 'Runs the brakeman security scanner'
task brakeman: :init_status do
sh 'mkdir -p metrics/brakeman'
sh 'brakeman -o metrics/brakeman/index.html .' do |ok, res|
puts '-' * 80
puts "Exited with status #{res.exitstatus}"
@metrics_exit = res.exitstatus unless ok
end
end
desc 'Runs rubycritic'
task rubycritic: :init_status do
sh 'mkdir -p metrics/rubycritic'
sh 'rubycritic -p metrics/rubycritic --mode-ci --no-browser app lib spec' do |ok, res|
puts '-' * 80
puts "Exited with status #{res.exitstatus}"
@metrics_exit = res.exitstatus unless ok
end
end
desc 'Runs rubocop'
task rubocop: :init_status do
sh 'mkdir -p metrics/rubocop'
sh "rubocop #{ENV['FIX'] && '-a'} -D -S --fail-level warn -f simple -f html -o metrics/rubocop/index.html ." do |ok, res|
puts '-' * 80
puts "Exited with status #{res.exitstatus}"
unless ok
@metrics_exit = res.exitstatus
raise 'Error running rubocop' if res.exitstatus == 2
end
end
end
desc 'Runs rails_best_practices'
task rails_best_practices: :init_status do
sh 'mkdir -p metrics/rails_best_practices'
sh 'rails_best_practices --spec -f html --output-file metrics/rails_best_practices/index.html lib app spec db' do |ok, res|
puts '-' * 80
puts "Exited with status #{res.exitstatus}"
unless ok
@metrics_exit = res.exitstatus
raise 'Error running rails_best_practices' unless ok
end
end
end
task :transmit_failure do
exit @metrics_exit unless @metrics_exit.zero?
end
desc 'Runs all code metrics'
task run: %i[brakeman rubycritic rubocop rails_best_practices transmit_failure]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment