Sha256: 0ad16e3daf5a93773fcce7ac550f38d90ed6bf84ebf7d13896f409ef0fddf970

Contents?: true

Size: 1.02 KB

Versions: 1

Compression:

Stored size: 1.02 KB

Contents

# frozen_string_literal: true

require_relative 'base_report'

module Reek
  module Report
    #
    # Displays smells as GitHub Workflow commands.
    #
    # @public
    #
    class GithubReport < BaseReport
      def show(out = $stdout)
        out.print(workflow_commands.join)
      end

      private

      def workflow_commands
        smells.map do |smell|
          WorkflowCommand.new(smell)
        end
      end

      # Represents a smell as a GitHub Workflow command.
      class WorkflowCommand
        def initialize(smell)
          @smell = smell
        end

        def to_s
          format(
            "::warning file=%<file>s,line=%<line>d::%<message>s\n",
            file: file,
            line: line,
            message: message)
        end

        private

        def file
          @smell.source
        end

        def line
          @smell.lines.first
        end

        def message
          @smell.base_message.gsub('%', '%25').gsub("\r", '%0D').gsub("\n", '%0A')
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
reek-6.4.0 lib/reek/report/github_report.rb