Sha256: ce1f87e6602f286b2cf5cc48a907dc9baf3f58e9f84ffc4a96c98f183b07bf4b

Contents?: true

Size: 1.1 KB

Versions: 5

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

require "pastel"

module Git
  module Lint
    module Reporters
      # Reports issues related to a single style.
      class Style
        def initialize analyzer, colorizer: Pastel.new
          @analyzer = analyzer
          @issue = analyzer.issue
          @colorizer = colorizer
        end

        def to_s = colorizer.public_send(color, message)

        private

        attr_reader :analyzer, :issue, :colorizer

        def message
          "  #{analyzer.class.label}#{severity_suffix}. " \
          "#{issue.fetch :hint}\n" \
          "#{affected_lines}"
        end

        def severity_suffix
          case analyzer.severity
            when :warn then " Warning"
            when :error then " Error"
            else ""
          end
        end

        def color
          case analyzer.severity
            when :warn then :yellow
            when :error then :red
            else :white
          end
        end

        def affected_lines
          issue.fetch(:lines, []).reduce("") { |lines, line| lines + Line.new(line).to_s }
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
git-lint-2.4.0 lib/git/lint/reporters/style.rb
git-lint-2.3.3 lib/git/lint/reporters/style.rb
git-lint-2.3.2 lib/git/lint/reporters/style.rb
git-lint-2.3.1 lib/git/lint/reporters/style.rb
git-lint-2.3.0 lib/git/lint/reporters/style.rb