Sha256: 2b6aaa0cd44afdb2ab7851546b2e24e2bdc3f95b21e379103dce4f1f59e3f7fc

Contents?: true

Size: 1.35 KB

Versions: 28

Compression:

Stored size: 1.35 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Formatter
    # This formatter formats report data as GitHub Workflow commands resulting
    # in GitHub check annotations when run within GitHub Actions.
    class GitHubActionsFormatter < BaseFormatter
      ESCAPE_MAP = { '%' => '%25', "\n" => '%0A', "\r" => '%0D' }.freeze

      def file_finished(file, offenses)
        offenses.each { |offense| report_offense(file, offense) }
      end

      private

      def github_escape(string)
        string.gsub(Regexp.union(ESCAPE_MAP.keys), ESCAPE_MAP)
      end

      def minimum_severity_to_fail
        @minimum_severity_to_fail ||= begin
          # Unless given explicitly as `fail_level`, `:info` severity offenses do not fail
          name = options.fetch(:fail_level, :refactor)
          RuboCop::Cop::Severity.new(name)
        end
      end

      def github_severity(offense)
        offense.severity < minimum_severity_to_fail ? 'warning' : 'error'
      end

      def report_offense(file, offense)
        output.printf(
          "\n::%<severity>s file=%<file>s,line=%<line>d,col=%<column>d::%<message>s\n",
          severity: github_severity(offense),
          file: PathUtil.smart_path(file),
          line: offense.line,
          column: offense.real_column,
          message: github_escape(offense.message)
        )
      end
    end
  end
end

Version data entries

28 entries across 28 versions & 4 rubygems

Version Path
scrapbook-0.3.2 vendor/ruby/2.7.0/gems/rubocop-1.26.0/lib/rubocop/formatter/git_hub_actions_formatter.rb
scrapbook-0.3.1 vendor/ruby/2.7.0/gems/rubocop-1.26.0/lib/rubocop/formatter/git_hub_actions_formatter.rb
rubocop-1.30.1 lib/rubocop/formatter/git_hub_actions_formatter.rb
rubocop-1.30.0 lib/rubocop/formatter/git_hub_actions_formatter.rb
rubocop-1.29.1 lib/rubocop/formatter/git_hub_actions_formatter.rb
rubocop-1.29.0 lib/rubocop/formatter/git_hub_actions_formatter.rb
rubocop-1.28.2 lib/rubocop/formatter/git_hub_actions_formatter.rb
rubocop-1.28.1 lib/rubocop/formatter/git_hub_actions_formatter.rb
rubocop-1.28.0 lib/rubocop/formatter/git_hub_actions_formatter.rb
rubocop-1.27.0 lib/rubocop/formatter/git_hub_actions_formatter.rb
rubocop-1.26.1 lib/rubocop/formatter/git_hub_actions_formatter.rb
op_connect-0.1.2 vendor/bundle/ruby/3.1.0/gems/rubocop-1.26.0/lib/rubocop/formatter/git_hub_actions_formatter.rb
rubocop-1.26.0 lib/rubocop/formatter/git_hub_actions_formatter.rb
rubocop-1.25.1 lib/rubocop/formatter/git_hub_actions_formatter.rb
rubocop-1.25.0 lib/rubocop/formatter/git_hub_actions_formatter.rb
phillipug-foodie-0.1.0 .vendor/ruby/3.0.0/gems/rubocop-1.24.0/lib/rubocop/formatter/git_hub_actions_formatter.rb
rubocop-1.24.1 lib/rubocop/formatter/git_hub_actions_formatter.rb
rubocop-1.24.0 lib/rubocop/formatter/git_hub_actions_formatter.rb
rubocop-1.23.0 lib/rubocop/formatter/git_hub_actions_formatter.rb
rubocop-1.22.3 lib/rubocop/formatter/git_hub_actions_formatter.rb