Class: RuboCop::Formatter::SARIFFormatter

Inherits:
BaseFormatter show all
Defined in:
lib/rubocop/formatter/sarif_formatter.rb

Overview

This formatter formats the report data in SARIF 2.1.0, the OASIS standard for static analysis results. It's understood by GitHub code scanning, Azure DevOps, and other tools that aggregate analyzer output.

SARIF only knows three severity levels, so RuboCop's info, refactor and convention severities are all reported as note.

Constant Summary collapse

SCHEMA_URI =
'https://json.schemastore.org/sarif-2.1.0.json'
SARIF_VERSION =
'2.1.0'
INFORMATION_URI =
'https://rubocop.org'
SEVERITY_LEVELS =
{
  info: 'note',
  refactor: 'note',
  convention: 'note',
  warning: 'warning',
  error: 'error',
  fatal: 'error'
}.freeze

Instance Attribute Summary

Attributes inherited from BaseFormatter

#options, #output

Instance Method Summary collapse

Methods inherited from BaseFormatter

#started

Constructor Details

#initialize(output, options = {}) ⇒ SARIFFormatter

Returns a new instance of SARIFFormatter.



27
28
29
30
31
32
33
34
# File 'lib/rubocop/formatter/sarif_formatter.rb', line 27

def initialize(output, options = {})
  super

  @rules = []
  @rule_indexes = {}
  @results = []
  @config_store = nil
end

Instance Method Details

#file_finished(file, offenses) ⇒ Object



40
41
42
43
44
# File 'lib/rubocop/formatter/sarif_formatter.rb', line 40

def file_finished(file, offenses)
  offenses.each do |offense|
    @results << result_for(file, offense)
  end
end

#file_started(_file, options) ⇒ Object



36
37
38
# File 'lib/rubocop/formatter/sarif_formatter.rb', line 36

def file_started(_file, options)
  @config_store = options[:config_store]
end

#finished(_inspected_files) ⇒ Object



46
47
48
# File 'lib/rubocop/formatter/sarif_formatter.rb', line 46

def finished(_inspected_files)
  output.write(report.to_json)
end