Sha256: 7608c874dd2954956d050833ed90d66ba5a20f9af3c416ebf144247a1b796ec3

Contents?: true

Size: 984 Bytes

Versions: 2

Compression:

Stored size: 984 Bytes

Contents

module SlimLint
  # Outputs report as a JSON document.
  class Reporter::JsonReporter < Reporter
    def report_lints
      grouped = lints.group_by(&:filename)

      report = {
        metadata: {
          slim_lint_version: SlimLint::VERSION,
          ruby_engine:      RUBY_ENGINE,
          ruby_patchlevel:  RUBY_PATCHLEVEL.to_s,
          ruby_platform:    RUBY_PLATFORM,
        },
        files: grouped.map { |l| map_file(l) },
        summary: {
          offense_count: lints.length,
          target_file_count: grouped.length,
          inspected_file_count: files.length,
        },
      }

      log.log report.to_json
    end

    private

    def map_file(file)
      {
        path: file.first,
        offenses: file.last.map { |o| map_offense(o) },
      }
    end

    def map_offense(offense)
      {
        severity: offense.severity,
        message: offense.message,
        location: {
          line: offense.line,
        },
      }
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
slim_lint-0.2.0 lib/slim_lint/reporter/json_reporter.rb
slim_lint-0.1.0 lib/slim_lint/reporter/json_reporter.rb