module Warnings::MessageUtil

Utility class to write the markdown and inline reports.

Constants

COLUMN_SEPARATOR
LINE_SEPARATOR
TABLE_HEADER
TABLE_SEPARATOR

Public Instance Methods

header() click to toggle source

Create the base table header line.

@return [String] String containing a markdown table header line.

# File lib/warnings/helper/message_util.rb, line 43
def header
  result = TABLE_HEADER.dup
  result << LINE_SEPARATOR
  result << TABLE_SEPARATOR
  result << LINE_SEPARATOR
end
header_name(report_name) click to toggle source

Create the report name string.

@param report_name [String] The name of the report. @return [String] Text containing header name of the report.

# File lib/warnings/helper/message_util.rb, line 36
def header_name(report_name)
  "# #{report_name}#{LINE_SEPARATOR}"
end
inline(issue) click to toggle source

Create an inline comment containing all issue information.

@param issue [Issue] The issue to report. @return String Text to add as comment.

# File lib/warnings/helper/message_util.rb, line 28
def inline(issue)
  "#{issue.severity.to_s.capitalize}\n#{meta_information(issue)}\n#{issue.message}"
end
issues(issues) click to toggle source

Create a string containing all issues prepared to be used in a markdown table.

@param issues [Array<Issue>] List of parsed issues. @return [String] String containing all issues. rubocop:disable Metrics/AbcSize

# File lib/warnings/helper/message_util.rb, line 55
def issues(issues)
  result = ''
  issues.each do |issue|
    result << COLUMN_SEPARATOR.dup
    result << issue.severity.to_s.capitalize
    result << COLUMN_SEPARATOR
    result << "#{issue.file_name}:#{issue.line}"
    result << COLUMN_SEPARATOR
    result << "#{meta_information(issue)} #{issue.message}"
    result << COLUMN_SEPARATOR
    result << LINE_SEPARATOR
  end
  # rubocop:enable Metrics/AbcSize
  result
end
markdown(name, issues) click to toggle source

Generate a markdown text message listing all issues as table.

@param name [String] The name of the report to be printed. @param issues [Array<Issue>] List of parsed issues. @return [String] String in danger markdown format.

# File lib/warnings/helper/message_util.rb, line 18
def markdown(name, issues)
  result = header_name(name)
  result << header
  result << issues(issues)
end
meta_information(issue) click to toggle source

Combine meta information about the issue. Meta information are considered infos about the check itself. e.g. category

@param issue [Issue] Issue to extract information. @return String combined information.

# File lib/warnings/helper/message_util.rb, line 77
def meta_information(issue)
  return unless issue.category

  result = '['
  result << issue.category
  result << ']'
end