Sha256: 6bd4130390817ed45143b25baaf0bf368e62963c2efb0a5d33071f57970b420e

Contents?: true

Size: 1.04 KB

Versions: 20

Compression:

Stored size: 1.04 KB

Contents

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,
        },
      }
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
slim_lint-0.15.1 lib/slim_lint/reporter/json_reporter.rb
slim_lint-0.15.0 lib/slim_lint/reporter/json_reporter.rb
slim_lint-0.14.0 lib/slim_lint/reporter/json_reporter.rb
slim_lint-0.13.0 lib/slim_lint/reporter/json_reporter.rb
slim_lint-0.12.0 lib/slim_lint/reporter/json_reporter.rb
slim_lint-0.11.0 lib/slim_lint/reporter/json_reporter.rb
slim_lint-0.10.0 lib/slim_lint/reporter/json_reporter.rb
slim_lint-0.9.0 lib/slim_lint/reporter/json_reporter.rb
slim_lint-0.8.3 lib/slim_lint/reporter/json_reporter.rb
slim_lint-0.8.2 lib/slim_lint/reporter/json_reporter.rb
slim_lint-0.8.1 lib/slim_lint/reporter/json_reporter.rb
slim_lint-0.8.0 lib/slim_lint/reporter/json_reporter.rb
slim_lint-0.7.2 lib/slim_lint/reporter/json_reporter.rb
slim_lint-0.7.1 lib/slim_lint/reporter/json_reporter.rb
slim_lint-0.7.0 lib/slim_lint/reporter/json_reporter.rb
slim_lint-0.6.1 lib/slim_lint/reporter/json_reporter.rb
slim_lint-0.6.0 lib/slim_lint/reporter/json_reporter.rb
slim_lint-0.5.0 lib/slim_lint/reporter/json_reporter.rb
slim_lint-0.4.0 lib/slim_lint/reporter/json_reporter.rb
slim_lint-0.3.0 lib/slim_lint/reporter/json_reporter.rb