class RuboCop::Formatter::GitHubActionsFormatter

This formatter formats report data as GitHub Workflow commands resulting in GitHub check annotations when run within GitHub Actions.

Constants

ESCAPE_MAP

Public Instance Methods

file_finished(file, offenses) click to toggle source
# File lib/rubocop/formatter/git_hub_actions_formatter.rb, line 14
def file_finished(file, offenses)
  @offenses_for_files[file] = offenses unless offenses.empty?
end
finished(_inspected_files) click to toggle source
# File lib/rubocop/formatter/git_hub_actions_formatter.rb, line 18
def finished(_inspected_files)
  @offenses_for_files.each do |file, offenses|
    offenses.each do |offense|
      report_offense(file, offense)
    end
  end
  output.puts
end
started(_target_files) click to toggle source
# File lib/rubocop/formatter/git_hub_actions_formatter.rb, line 10
def started(_target_files)
  @offenses_for_files = {}
end

Private Instance Methods

github_escape(string) click to toggle source
# File lib/rubocop/formatter/git_hub_actions_formatter.rb, line 29
def github_escape(string)
  string.gsub(Regexp.union(ESCAPE_MAP.keys), ESCAPE_MAP)
end
github_severity(offense) click to toggle source
# File lib/rubocop/formatter/git_hub_actions_formatter.rb, line 41
def github_severity(offense)
  offense.severity < minimum_severity_to_fail ? 'warning' : 'error'
end
minimum_severity_to_fail() click to toggle source
# File lib/rubocop/formatter/git_hub_actions_formatter.rb, line 33
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
report_offense(file, offense) click to toggle source
# File lib/rubocop/formatter/git_hub_actions_formatter.rb, line 45
def report_offense(file, offense)
  output.printf(
    "\n::%<severity>s file=%<file>s,line=%<line>d,col=%<column>d::%<message>s",
    severity: github_severity(offense),
    file: PathUtil.smart_path(file),
    line: offense.line,
    column: offense.real_column,
    message: github_escape(offense.message)
  )
end