Sha256: a3c9751f3635457336131bc727c76dc412d3877ac4adc0958e6a23b5b299a43c

Contents?: true

Size: 1.2 KB

Versions: 2

Compression:

Stored size: 1.2 KB

Contents

# typed: strict
# frozen_string_literal: true

require "benchmark"
require "sorbet-runtime"

require "packwerk/inflector"
require "packwerk/output_style"
require "packwerk/output_styles/plain"

module Packwerk
  module Formatters
    class OffensesFormatter
      extend T::Sig

      sig { params(style: OutputStyle).void }
      def initialize(style: OutputStyles::Plain.new)
        @style = style
      end

      sig { params(offenses: T::Array[T.nilable(Offense)]).returns(String) }
      def show_offenses(offenses)
        return "No offenses detected 🎉" if offenses.empty?

        <<~EOS
          #{offenses_list(offenses)}
          #{offenses_summary(offenses)}
        EOS
      end

      private

      sig { params(offenses: T::Array[T.nilable(Offense)]).returns(String) }
      def offenses_list(offenses)
        offenses
          .compact
          .map { |offense| offense.to_s(@style) }
          .join("\n")
      end

      sig { params(offenses: T::Array[T.nilable(Offense)]).returns(String) }
      def offenses_summary(offenses)
        offenses_string = Inflector.default.pluralize("offense", offenses.length)
        "#{offenses.length} #{offenses_string} detected"
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
packwerk-1.1.3 lib/packwerk/formatters/offenses_formatter.rb
packwerk-1.1.2 lib/packwerk/formatters/offenses_formatter.rb