Sha256: 67c6892fce2ec18a310106b4eeed6a8f11e4e6d612553849cbd249d65c49a3e5

Contents?: true

Size: 1.74 KB

Versions: 28

Compression:

Stored size: 1.74 KB

Contents

# frozen_string_literal: true

module ThemeCheck
  class Printer
    def print(theme, offenses, auto_correct)
      offenses.each do |offense|
        print_offense(offense, auto_correct)
        puts
      end

      correctable = offenses.select(&:correctable?)
      puts "#{theme.all.size} files inspected, #{red(offenses.size.to_s + ' offenses')} detected, \
#{yellow(correctable.size.to_s + ' offenses')} #{auto_correct ? 'corrected' : 'auto-correctable'}"
    end

    def print_offense(offense, auto_correct)
      location = if offense.location
        blue(offense.location) + ": "
      else
        ""
      end

      corrected = if auto_correct && offense.correctable?
        green("[Corrected] ")
      else
        ""
      end

      puts location +
        colorized_severity(offense.severity) + ": " +
        yellow(offense.check_name) + ": " +
        corrected +
        offense.message + "."
      if offense.source_excerpt
        puts "\t#{offense.source_excerpt}"
        if offense.markup_start_in_excerpt
          puts "\t" + (" " * offense.markup_start_in_excerpt) + ("^" * offense.markup.size)
        end
      end
    end

    private

    def colorize(str, color_code)
      "\e[#{color_code}m#{str}\e[0m"
    end

    def colorized_severity(severity)
      case severity
      when :error
        red(severity)
      when :suggestion
        pink(severity)
      when :style
        light_blue(severity)
      end
    end

    def red(str)
      colorize(str, 31)
    end

    def green(str)
      colorize(str, 32)
    end

    def yellow(str)
      colorize(str, 33)
    end

    def blue(str)
      colorize(str, 34)
    end

    def pink(str)
      colorize(str, 35)
    end

    def light_blue(str)
      colorize(str, 36)
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
theme-check-1.5.0 lib/theme_check/printer.rb
theme-check-1.4.0 lib/theme_check/printer.rb
theme-check-1.3.0 lib/theme_check/printer.rb
theme-check-1.2.0 lib/theme_check/printer.rb
theme-check-1.1.0 lib/theme_check/printer.rb
theme-check-1.0.0 lib/theme_check/printer.rb
theme-check-0.10.2 lib/theme_check/printer.rb
theme-check-0.10.1 lib/theme_check/printer.rb
theme-check-0.10.0 lib/theme_check/printer.rb
theme-check-0.9.1 lib/theme_check/printer.rb
theme-check-0.9.0 lib/theme_check/printer.rb
theme-check-0.8.3 lib/theme_check/printer.rb
theme-check-0.8.2 lib/theme_check/printer.rb
theme-check-0.8.1 lib/theme_check/printer.rb
theme-check-0.8.0 lib/theme_check/printer.rb
theme-check-0.7.3 lib/theme_check/printer.rb
theme-check-0.7.2 lib/theme_check/printer.rb
theme-check-0.7.1 lib/theme_check/printer.rb
theme-check-0.7.0 lib/theme_check/printer.rb
theme-check-0.6.0 lib/theme_check/printer.rb