Sha256: ea2e932594385cabd11bc8b91d606c4adc969105f181f2a8ba509df12040d4bb

Contents?: true

Size: 877 Bytes

Versions: 25

Compression:

Stored size: 877 Bytes

Contents

# frozen_string_literal: true

require "boxt_ruby_style_guide"
require "boxt_ruby_style_guide/filepath_matcher"
require "boxt_ruby_style_guide/git_diff"
require "rubocop"

namespace :lint do
  desc "Runs rubocop against all files with committed changes different from base branch"
  task :rubocop do
    file_paths = sanitized_file_paths
    puts "File paths: #{file_paths.join(', ')}"

    if file_paths.any?
      auto_flag_opt = ARGV.select { |a| ["-a", "-A"].include?(a) }.first
      exec("bundle exec rubocop #{file_paths.join(' ')} #{auto_flag_opt}".strip)
    else
      puts "No Ruby files changed"
    end
  end
end

private

# Returns an array of files
def sanitized_file_paths
  base = ENV.fetch("RUBOCOP_LINT_BASE", "main")
  changed_files = BoxtRubyStyleGuide::GitDiff.new(base: base).all
  BoxtRubyStyleGuide::FilepathMatcher.new(*changed_files).all_matches
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
boxt_ruby_style_guide-8.6.0 lib/tasks/lint.rake
boxt_ruby_style_guide-8.5.1 lib/tasks/lint.rake
boxt_ruby_style_guide-8.5.0 lib/tasks/lint.rake
boxt_ruby_style_guide-8.4.1 lib/tasks/lint.rake
boxt_ruby_style_guide-8.4.0 lib/tasks/lint.rake
boxt_ruby_style_guide-8.3.6 lib/tasks/lint.rake
boxt_ruby_style_guide-8.3.5 lib/tasks/lint.rake
boxt_ruby_style_guide-8.3.4 lib/tasks/lint.rake
boxt_ruby_style_guide-8.3.3 lib/tasks/lint.rake
boxt_ruby_style_guide-8.3.2 lib/tasks/lint.rake
boxt_ruby_style_guide-8.3.1 lib/tasks/lint.rake
boxt_ruby_style_guide-8.3.0 lib/tasks/lint.rake
boxt_ruby_style_guide-8.2.3 lib/tasks/lint.rake
boxt_ruby_style_guide-8.2.2 lib/tasks/lint.rake
boxt_ruby_style_guide-8.2.1 lib/tasks/lint.rake
boxt_ruby_style_guide-8.2.0 lib/tasks/lint.rake
boxt_ruby_style_guide-8.1.1 lib/tasks/lint.rake
boxt_ruby_style_guide-8.1.0 lib/tasks/lint.rake
boxt_ruby_style_guide-8.0.0 lib/tasks/lint.rake
boxt_ruby_style_guide-7.10.0 lib/tasks/lint.rake