Sha256: d6268d3075a80d972fd33ad56bc027aeba62158df40dd7a11822621913c68d91

Contents?: true

Size: 1.23 KB

Versions: 31

Compression:

Stored size: 1.23 KB

Contents

# frozen_string_literal: true

module Reek
  module Report
    #
    # Base class for heading formatters.
    # Is responsible for formatting the heading emitted for each examiner
    #
    # @abstract Override {#show_header?} to implement a heading formatter.
    class HeadingFormatterBase
      # @quality :reek:UtilityFunction
      def show_header?(_examiner)
        raise NotImplementedError
      end

      def header(examiner)
        if show_header?(examiner)
          formatted_header examiner
        else
          ''
        end
      end

      private

      def formatted_header(examiner)
        count = examiner.smells_count
        result = Rainbow("#{examiner.origin} -- ").cyan +
          Rainbow("#{count} warning").yellow
        result += Rainbow('s').yellow unless count == 1
        result
      end
    end

    #
    # Lists out each examiner, even if it has no smell
    #
    class VerboseHeadingFormatter < HeadingFormatterBase
      def show_header?(_examiner)
        true
      end
    end

    #
    # Lists only smelly examiners
    #
    class QuietHeadingFormatter < HeadingFormatterBase
      # @quality :reek:UtilityFunction
      def show_header?(examiner)
        examiner.smelly?
      end
    end
  end
end

Version data entries

31 entries across 29 versions & 2 rubygems

Version Path
reek-6.4.0 lib/reek/report/heading_formatter.rb
reek-6.3.0 lib/reek/report/heading_formatter.rb
reek-6.2.0 lib/reek/report/heading_formatter.rb
reek-6.1.4 lib/reek/report/heading_formatter.rb
reek-6.1.3 lib/reek/report/heading_formatter.rb
reek-6.1.2 lib/reek/report/heading_formatter.rb
reek-6.1.1 lib/reek/report/heading_formatter.rb
reek-6.1.0 lib/reek/report/heading_formatter.rb
reek-6.0.6 lib/reek/report/heading_formatter.rb
reek-6.0.5 lib/reek/report/heading_formatter.rb
reek-6.0.4 lib/reek/report/heading_formatter.rb
reek-6.0.3 lib/reek/report/heading_formatter.rb
reek-6.0.2 lib/reek/report/heading_formatter.rb
reek-6.0.1 lib/reek/report/heading_formatter.rb
reek-6.0.0 lib/reek/report/heading_formatter.rb
reek-5.6.0 lib/reek/report/heading_formatter.rb
reek-5.5.0 lib/reek/report/heading_formatter.rb
reek-5.4.1 lib/reek/report/heading_formatter.rb
reek-5.4.0 lib/reek/report/heading_formatter.rb
reek-5.3.2 lib/reek/report/heading_formatter.rb