Sha256: ec2f4c448165dc969ed4a58b526b0cb32eb74d69f2613c8f9ff39131bbcb2c59

Contents?: true

Size: 1.55 KB

Versions: 51

Compression:

Stored size: 1.55 KB

Contents

# frozen_string_literal: true

module RuboCop
  module Formatter
    # This formatter formats report data in clang style.
    # The precise location of the problem is shown together with the
    # relevant source code.
    class ClangStyleFormatter < SimpleTextFormatter
      ELLIPSES = '...'

      def report_file(file, offenses)
        offenses.each { |offense| report_offense(file, offense) }
      end

      private

      def report_offense(file, offense)
        output.printf(
          "%<path>s:%<line>d:%<column>d: %<severity>s: %<message>s\n",
          path: cyan(smart_path(file)),
          line: offense.line,
          column: offense.real_column,
          severity: colored_severity_code(offense),
          message: message(offense)
        )

        begin
          return unless valid_line?(offense)

          report_line(offense.location)
          report_highlighted_area(offense.highlighted_area)
        rescue IndexError
          # range is not on a valid line; perhaps the source file is empty
        end
      end

      def valid_line?(offense)
        !offense.location.source_line.blank?
      end

      def report_line(location)
        source_line = location.source_line

        if location.first_line == location.last_line
          output.puts(source_line)
        else
          output.puts("#{source_line} #{yellow(ELLIPSES)}")
        end
      end

      def report_highlighted_area(highlighted_area)
        output.puts("#{' ' * highlighted_area.begin_pos}" \
                    "#{'^' * highlighted_area.size}")
      end
    end
  end
end

Version data entries

51 entries across 51 versions & 5 rubygems

Version Path
plaid-14.13.0 vendor/bundle/ruby/3.0.0/gems/rubocop-0.91.1/lib/rubocop/formatter/clang_style_formatter.rb
plaid-14.12.1 vendor/bundle/ruby/3.0.0/gems/rubocop-0.91.1/lib/rubocop/formatter/clang_style_formatter.rb
plaid-14.12.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/formatter/clang_style_formatter.rb
plaid-14.11.1 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/formatter/clang_style_formatter.rb
plaid-14.10.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/formatter/clang_style_formatter.rb
plaid-14.7.0 vendor/bundle/ruby/2.6.0/gems/rubocop-0.91.1/lib/rubocop/formatter/clang_style_formatter.rb
rubocop-1.12.0 lib/rubocop/formatter/clang_style_formatter.rb
rubocop-1.11.0 lib/rubocop/formatter/clang_style_formatter.rb
rubocop-1.10.0 lib/rubocop/formatter/clang_style_formatter.rb
rubocop-1.9.1 lib/rubocop/formatter/clang_style_formatter.rb
rubocop-1.9.0 lib/rubocop/formatter/clang_style_formatter.rb
rubocop-1.8.1 lib/rubocop/formatter/clang_style_formatter.rb
rubocop-1.8.0 lib/rubocop/formatter/clang_style_formatter.rb
rubocop-1.7.0 lib/rubocop/formatter/clang_style_formatter.rb
rubocop-1.6.1 lib/rubocop/formatter/clang_style_formatter.rb
rubocop-1.6.0 lib/rubocop/formatter/clang_style_formatter.rb
rubocop-1.5.2 lib/rubocop/formatter/clang_style_formatter.rb
rubocop-1.5.1 lib/rubocop/formatter/clang_style_formatter.rb
rubocop-1.5.0 lib/rubocop/formatter/clang_style_formatter.rb
rubocop-1.4.2 lib/rubocop/formatter/clang_style_formatter.rb