Sha256: 8084f319a68e6d682433dc51b7695627aedc15e532de906f1af8270cbca50c58

Contents?: true

Size: 1.06 KB

Versions: 15

Compression:

Stored size: 1.06 KB

Contents

# frozen_string_literal: true

require 'pastel'

module Chutney
  # pretty formatter
  class RainbowFormatter < Formatter
    def initialize
      super

      @pastel = Pastel.new
    end

    def format
      files_with_issues.each do |file, linter|
        put_file(file)
        linter.filter { |l| !l[:issues].empty? }.each do |linter_with_issues|
          put_linter(linter_with_issues)
          linter_with_issues[:issues].each { |i| put_issue(file, i) }
        end
      end
      put_summary
    end

    def put_file(file)
      puts @pastel.cyan(file.to_s)
    end

    def put_linter(linter)
      puts @pastel.red("  #{linter[:linter]}")
    end

    def put_issue(file, issue)
      puts "    #{issue[:message]}"
      puts "    #{@pastel.dim file.to_s}:#{@pastel.dim(issue.dig(:location, :line))}"
    end

    def put_summary
      print "#{files.count} features inspected, "
      if files_with_issues.count.zero?
        puts @pastel.green('all taste delicious')
      else
        puts @pastel.red("#{files_with_issues.count} taste nasty")
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
chutney-3.10.0 lib/chutney/formatter/rainbow_formatter.rb
chutney-3.9.0 lib/chutney/formatter/rainbow_formatter.rb
chutney-3.8.2 lib/chutney/formatter/rainbow_formatter.rb
chutney-3.8.1 lib/chutney/formatter/rainbow_formatter.rb
chutney-3.8.0 lib/chutney/formatter/rainbow_formatter.rb
chutney-3.7.0 lib/chutney/formatter/rainbow_formatter.rb
chutney-3.6.0 lib/chutney/formatter/rainbow_formatter.rb
chutney-3.5.0 lib/chutney/formatter/rainbow_formatter.rb
chutney-3.3.0 lib/chutney/formatter/rainbow_formatter.rb
chutney-3.2.1 lib/chutney/formatter/rainbow_formatter.rb
chutney-3.2.0 lib/chutney/formatter/rainbow_formatter.rb
chutney-3.1.1 lib/chutney/formatter/rainbow_formatter.rb
chutney-3.1.0 lib/chutney/formatter/rainbow_formatter.rb
chutney-3.0.1 lib/chutney/formatter/rainbow_formatter.rb
chutney-3.0.0 lib/chutney/formatter/rainbow_formatter.rb