Class: RuboCop::Formatter::GitLabFormatter
- Inherits:
-
BaseFormatter
- Object
- BaseFormatter
- RuboCop::Formatter::GitLabFormatter
- Includes:
- PathUtil
- Defined in:
- lib/rubocop/formatter/gitlab_formatter.rb
Overview
A very simple RuboCop formatter for use with GitLab code quality artifact
Constant Summary collapse
- SEVERITY_MAPPING =
{ I: 'info', R: 'minor', C: 'minor', W: 'major', E: 'critical', F: 'blocker' }.freeze
Instance Attribute Summary collapse
-
#output_array ⇒ Object
readonly
Returns the value of attribute output_array.
Instance Method Summary collapse
- #file_finished(file, offenses) ⇒ Object
- #finished(_inspected_files) ⇒ Object
- #hash_for_location(file, location) ⇒ Object
- #hash_for_offense(file, offense) ⇒ Object
-
#initialize(output, options = {}) ⇒ GitLabFormatter
constructor
A new instance of GitLabFormatter.
Constructor Details
#initialize(output, options = {}) ⇒ GitLabFormatter
Returns a new instance of GitLabFormatter.
24 25 26 27 28 |
# File 'lib/rubocop/formatter/gitlab_formatter.rb', line 24 def initialize(output, = {}) super @output_array = [] end |
Instance Attribute Details
#output_array ⇒ Object (readonly)
Returns the value of attribute output_array.
22 23 24 |
# File 'lib/rubocop/formatter/gitlab_formatter.rb', line 22 def output_array @output_array end |
Instance Method Details
#file_finished(file, offenses) ⇒ Object
30 31 32 33 34 |
# File 'lib/rubocop/formatter/gitlab_formatter.rb', line 30 def file_finished(file, offenses) offenses.each do |offense| output_array << hash_for_offense(file, offense) end end |
#finished(_inspected_files) ⇒ Object
36 37 38 |
# File 'lib/rubocop/formatter/gitlab_formatter.rb', line 36 def finished(_inspected_files) output.write output_array.to_json end |
#hash_for_location(file, location) ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'lib/rubocop/formatter/gitlab_formatter.rb', line 49 def hash_for_location(file, location) { path: smart_path(file), lines: { begin: location.line } } end |
#hash_for_offense(file, offense) ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/rubocop/formatter/gitlab_formatter.rb', line 40 def hash_for_offense(file, offense) { description: offense., fingerprint: offense.hash, severity: SEVERITY_MAPPING[offense.severity.code.to_sym], location: hash_for_location(file, offense.location) } end |