Sha256: 97c61e88ad9ca841831b3b7d6e827c7d322d87c3c552282763f5f9b74112fc9e

Contents?: true

Size: 1.1 KB

Versions: 14

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

module SlimLint
  # Outputs report as a JSON document.
  class Reporter::JsonReporter < Reporter
    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,
        },
      }

      log.log report_hash.to_json
    end

    private

    def metadata
      {
        slim_lint_version: SlimLint::VERSION,
        ruby_engine: RUBY_ENGINE,
        ruby_patchlevel: RUBY_PATCHLEVEL.to_s,
        ruby_platform: RUBY_PLATFORM,
      }
    end

    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,
        },
        linter: offense.linter&.name,
      }
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
slim_lint-0.31.1 lib/slim_lint/reporter/json_reporter.rb
slim_lint-0.31.0 lib/slim_lint/reporter/json_reporter.rb
slim_lint-0.30.0 lib/slim_lint/reporter/json_reporter.rb
slim_lint-0.29.0 lib/slim_lint/reporter/json_reporter.rb
slim_lint-0.28.0 lib/slim_lint/reporter/json_reporter.rb
slim_lint-0.27.0 lib/slim_lint/reporter/json_reporter.rb
slim_lint-0.26.0 lib/slim_lint/reporter/json_reporter.rb
slim_lint-0.25.0 lib/slim_lint/reporter/json_reporter.rb
slim_lint-0.24.0 lib/slim_lint/reporter/json_reporter.rb
slim_lint-0.23.0 lib/slim_lint/reporter/json_reporter.rb
slim_lint-0.22.1 lib/slim_lint/reporter/json_reporter.rb
slim_lint-0.22.0 lib/slim_lint/reporter/json_reporter.rb
slim_lint-0.21.1 lib/slim_lint/reporter/json_reporter.rb
slim_lint-0.21.0 lib/slim_lint/reporter/json_reporter.rb