Sha256: 9d9cea2d0de95a2eace34756697f1e623f4e4e7078e132cdcff06adc43b8845b

Contents?: true

Size: 1.93 KB

Versions: 1

Compression:

Stored size: 1.93 KB

Contents

namespace :rubocop do
  require 'ndr_dev_support/rubocop/range_finder'
  require 'ndr_dev_support/rubocop/range_augmenter'
  require 'ndr_dev_support/rubocop/executor'
  require 'ndr_dev_support/rubocop/reporter'

  # For a given set of change locations (extract from a diff),
  # run rubocop on the relevant files, and report filtered results.
  def rubocop_file_ranges(file_ranges)
    output  = {}
    threads = file_ranges.map do |file, ranges|
      Thread.new do
        # Expand ranges to include entire methods, etc:
        lines = NdrDevSupport::Rubocop::RangeAugmenter.new(file, ranges).augmented_lines
        # Get rubocop output for those files:
        output[file] = NdrDevSupport::Rubocop::Executor.new(file, lines).output
      end
    end
    threads.each(&:join)

    # Report on output:
    exit NdrDevSupport::Rubocop::Reporter.new(output).report
  end

  desc <<-USAGE
    Usage:
      rake rubocop:diff HEAD
      rake rubocop:diff HEAD~3..HEAD~2
      rake rubocop:diff HEAD~3..HEAD~2
      rake rubocop:diff aef12fd4
      rake rubocop:diff master
  USAGE
  task :diff do
    expr   = ARGV[1..-1].join(' ')
    ranges = NdrDevSupport::Rubocop::RangeFinder.new.diff_expr(expr)
    rubocop_file_ranges ranges
  end

  namespace :diff do
    desc 'Usage: rake rubocop:diff:head'
    task :head do
      rubocop_file_ranges NdrDevSupport::Rubocop::RangeFinder.new.diff_head
    end

    desc 'Usage: rake rubocop:diff:unstaged'
    task :unstaged do
      rubocop_file_ranges NdrDevSupport::Rubocop::RangeFinder.new.diff_unstaged
    end

    desc 'Usage: rake rubocop:diff:staged'
    task :staged do
      rubocop_file_ranges NdrDevSupport::Rubocop::RangeFinder.new.diff_staged
    end

    desc 'Usage: rake rubocop:diff:file file [,file]'
    task :file do
      files = ARGV.uniq.select { |file| File.exist?(file) }

      file_ranges = NdrDevSupport::Rubocop::RangeFinder.new.diff_files(files)
      rubocop_file_ranges(file_ranges)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ndr_dev_support-1.1.1 lib/tasks/rubocop.rake