Sha256: cdeaecfece58abbd57fac929eb3be8414069017545a7f001e680f5b3879e2615

Contents?: true

Size: 1.08 KB

Versions: 20

Compression:

Stored size: 1.08 KB

Contents

# frozen_string_literal: true

module Git
  module Lint
    module Reporters
      # Reports issues related to a single style.
      class Style
        include Import[:color]

        def initialize(analyzer, **)
          super(**)
          @analyzer = analyzer
          @issue = analyzer.issue
        end

        def to_s = color[message, style]

        alias to_str to_s

        private

        attr_reader :analyzer, :issue

        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 style
          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) }
        end
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
git-lint-8.8.0 lib/git/lint/reporters/style.rb
git-lint-8.7.0 lib/git/lint/reporters/style.rb
git-lint-8.6.0 lib/git/lint/reporters/style.rb
git-lint-8.5.0 lib/git/lint/reporters/style.rb
git-lint-8.4.0 lib/git/lint/reporters/style.rb
git-lint-8.3.0 lib/git/lint/reporters/style.rb
git-lint-8.2.0 lib/git/lint/reporters/style.rb
git-lint-8.1.0 lib/git/lint/reporters/style.rb
git-lint-8.0.0 lib/git/lint/reporters/style.rb
git-lint-7.5.0 lib/git/lint/reporters/style.rb
git-lint-7.3.0 lib/git/lint/reporters/style.rb
git-lint-7.2.0 lib/git/lint/reporters/style.rb
git-lint-7.1.0 lib/git/lint/reporters/style.rb
git-lint-7.0.0 lib/git/lint/reporters/style.rb
git-lint-6.2.1 lib/git/lint/reporters/style.rb
git-lint-6.2.0 lib/git/lint/reporters/style.rb
git-lint-6.1.0 lib/git/lint/reporters/style.rb
git-lint-6.0.2 lib/git/lint/reporters/style.rb
git-lint-6.0.1 lib/git/lint/reporters/style.rb
git-lint-6.0.0 lib/git/lint/reporters/style.rb