Sha256: 8cef7568c842adfa2a7a4936f2d4ff2b49d3309a5efc1711cea4b017cdb181ee

Contents?: true

Size: 1.1 KB

Versions: 23

Compression:

Stored size: 1.1 KB

Contents

# frozen_string_literal: true

require 'rexml/document'

module SlimLint
  # Outputs report as a Checkstyle XML document.
  class Reporter::CheckstyleReporter < Reporter
    def display_report(report)
      document = REXML::Document.new.tap do |d|
        d << REXML::XMLDecl.new
      end
      checkstyle = REXML::Element.new('checkstyle', document)

      report.lints.group_by(&:filename).map do |lint|
        map_file(lint, checkstyle)
      end

      log.log document.to_s
    end

    private

    def map_file(file, checkstyle)
      REXML::Element.new('file', checkstyle).tap do |f|
        path_name = file.first
        path_name = relative_path(file) if defined?(relative_path)
        f.attributes['name'] = path_name

        file.last.map { |o| map_offense(o, f) }
      end
    end

    def map_offense(offence, parent)
      REXML::Element.new('error', parent).tap do |e|
        e.attributes['line'] = offence.line
        e.attributes['severity'] = offence.error? ? 'error' : 'warning'
        e.attributes['message'] = offence.message
        e.attributes['source'] = 'slim-lint'
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
slim_lint-0.31.1 lib/slim_lint/reporter/checkstyle_reporter.rb
slim_lint-0.31.0 lib/slim_lint/reporter/checkstyle_reporter.rb
slim_lint-0.30.0 lib/slim_lint/reporter/checkstyle_reporter.rb
slim_lint-0.29.0 lib/slim_lint/reporter/checkstyle_reporter.rb
slim_lint-0.28.0 lib/slim_lint/reporter/checkstyle_reporter.rb
slim_lint-0.27.0 lib/slim_lint/reporter/checkstyle_reporter.rb
slim_lint-0.26.0 lib/slim_lint/reporter/checkstyle_reporter.rb
slim_lint-0.25.0 lib/slim_lint/reporter/checkstyle_reporter.rb
slim_lint-0.24.0 lib/slim_lint/reporter/checkstyle_reporter.rb
slim_lint-0.23.0 lib/slim_lint/reporter/checkstyle_reporter.rb
slim_lint-0.22.1 lib/slim_lint/reporter/checkstyle_reporter.rb
slim_lint-0.22.0 lib/slim_lint/reporter/checkstyle_reporter.rb
slim_lint-0.21.1 lib/slim_lint/reporter/checkstyle_reporter.rb
slim_lint-0.21.0 lib/slim_lint/reporter/checkstyle_reporter.rb
slim_lint-0.20.2 lib/slim_lint/reporter/checkstyle_reporter.rb
slim_lint-0.20.1 lib/slim_lint/reporter/checkstyle_reporter.rb
slim_lint-0.20.0 lib/slim_lint/reporter/checkstyle_reporter.rb
slim_lint-0.19.0 lib/slim_lint/reporter/checkstyle_reporter.rb
slim_lint-0.18.0 lib/slim_lint/reporter/checkstyle_reporter.rb
slim_lint-0.17.1 lib/slim_lint/reporter/checkstyle_reporter.rb