class GemOf::LintTasks

various lint-oriented tasks

Public Class Methods

new() click to toggle source

instance lint takss in namespace :lint @api public @example LintTasks.new

# File lib/gem_of/rake_tasks.rb, line 149
def initialize
  namespace :lint do
    desc "check number of lines of code changed. No long PRs"
    task "diff_length" do
      diff_length? exit diff_length: exit
    end

    # this will produce 'test:rubocop','test:rubocop:auto_correct' tasks
    RuboCop::RakeTask.new do |task|
      task.options = ["--debug"]
    end

    # this will produce the 'test:flog' task
    allowed_complexity = 585 # <cough!>
    FlogTask.new :flog, allowed_complexity, %w[lib]
    # this will produce the 'test:flay' task
    allowed_repitition = 0
    FlayTask.new :flay, allowed_repitition, %w[lib]
    # this will produce the 'test:roodi' task
    RoodiTask.new
    # this will produce the 'test:rubycritic' task
    RubyCritic::RakeTask.new do |task|
      task.paths   = FileList["lib/**/*.rb"]
    end
  end
end

Private Instance Methods

diff_length() click to toggle source

@api private

# File lib/gem_of/rake_tasks.rb, line 179
def diff_length
  max_length = 150
  target_branch = ENV["DISTELLI_RELBRANCH"] || "master"
  diff_cmd = "git diff --numstat #{target_branch}"
  sum_cmd  = "awk '{s+=$1} END {print s}'"
  diff_len = `#{diff_cmd} | #{sum_cmd}`.to_i
  if diff_len < max_length
    puts "diff length (#{diff_len}) is less than #{max_length} LoC"
    return
  else
    puts "diff length (#{diff_len}) is more than #{max_length} LoC"
    return diff_len
  end
end