class HamlLint::Reporter::HashReporter

Outputs report as a Ruby Hash for easy use by other tools.

Public Class Methods

available?() click to toggle source

Disables this reporter on the CLI since it doesn't output anything.

@return [false]

# File lib/haml_lint/reporter/hash_reporter.rb, line 9
def self.available?
  false
end

Public Instance Methods

display_report(report) click to toggle source
# File lib/haml_lint/reporter/hash_reporter.rb, line 13
def display_report(report)
  lints = report.lints
  grouped = lints.group_by(&:filename)

  report_hash = {
    metadata: metadata,
    files: grouped.map { |l| map_file(l) },
    summary: {
      offense_count: lints.length,
      target_file_count: grouped.length,
      inspected_file_count: report.files.length,
    },
  }

  report_hash
end

Private Instance Methods

map_file(file) click to toggle source
# File lib/haml_lint/reporter/hash_reporter.rb, line 41
def map_file(file)
  {
    path: file.first,
    offenses: file.last.map { |o| map_offense(o) },
  }
end
map_offense(offense) click to toggle source
# File lib/haml_lint/reporter/hash_reporter.rb, line 48
def map_offense(offense)
  {
    severity: offense.severity,
    message: offense.message,
    location: {
      line: offense.line,
    },
  }.tap do |h|
    h[:linter_name] = offense.linter.name if offense.linter
  end
end
metadata() click to toggle source
# File lib/haml_lint/reporter/hash_reporter.rb, line 32
def metadata
  {
    haml_lint_version: HamlLint::VERSION,
    ruby_engine:      RUBY_ENGINE,
    ruby_patchlevel:  RUBY_PATCHLEVEL.to_s,
    ruby_platform:    RUBY_PLATFORM,
  }
end