Class: RuboCop::Formatter::GitHubActionsFormatter
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
BaseFormatter
|
|
Instance Chain:
self,
BaseFormatter
|
|
Inherits: |
RuboCop::Formatter::BaseFormatter
|
Defined in: | lib/rubocop/formatter/github_actions_formatter.rb |
Overview
This formatter formats report data as GitHub Workflow commands resulting in GitHub check annotations when run within GitHub Actions.
Constant Summary
-
ESCAPE_MAP =
# File 'lib/rubocop/formatter/github_actions_formatter.rb', line 8{ '%' => '%25', "\n" => '%0A', "\r" => '%0D' }.freeze
Class Method Summary
BaseFormatter
- Inherited
Instance Attribute Summary
BaseFormatter
- Inherited
Instance Method Summary
- #file_finished(file, offenses)
- #finished(_inspected_files)
- #started(_target_files)
- #github_escape(string) private
- #github_severity(offense) private
- #minimum_severity_to_fail private
- #report_offense(file, offense) private
BaseFormatter
- Inherited
#file_finished | Invoked at the end of inspecting each files. |
#file_started | Invoked at the beginning of inspecting each files. |
#finished | Invoked after all files are inspected or interrupted by user. |
#started | Invoked once before any files are inspected. |
Constructor Details
This class inherits a constructor from RuboCop::Formatter::BaseFormatter
Instance Method Details
#file_finished(file, offenses)
[ GitHub ]# File 'lib/rubocop/formatter/github_actions_formatter.rb', line 14
def file_finished(file, offenses) @offenses_for_files[file] = offenses unless offenses.empty? end
#finished(_inspected_files)
[ GitHub ]# File 'lib/rubocop/formatter/github_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
#github_escape(string) (private)
[ GitHub ]# File 'lib/rubocop/formatter/github_actions_formatter.rb', line 29
def github_escape(string) string.gsub(Regexp.union(ESCAPE_MAP.keys), ESCAPE_MAP) end
#github_severity(offense) (private)
[ GitHub ]# File 'lib/rubocop/formatter/github_actions_formatter.rb', line 41
def github_severity(offense) offense.severity < minimum_severity_to_fail ? 'warning' : 'error' end
#minimum_severity_to_fail (private)
[ GitHub ]#report_offense(file, offense) (private)
[ GitHub ]# File 'lib/rubocop/formatter/github_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. ) ) end
#started(_target_files)
[ GitHub ]# File 'lib/rubocop/formatter/github_actions_formatter.rb', line 10
def started(_target_files) @offenses_for_files = {} end