Sha256: 4a3589ff44588749cb2c8a3e1cb61439ee7cbf300059f0c857c66d751266ad51

Contents?: true

Size: 1.56 KB

Versions: 19

Compression:

Stored size: 1.56 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)
        )

        return unless valid_line?(offense)

        report_line(offense.location)
        report_highlighted_area(offense.highlighted_area)
      end

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

      def report_line(location)
        source_line = location.source_line

        if location.single_line?
          output.puts(source_line)
        else
          output.puts("#{source_line} #{yellow(ELLIPSES)}")
        end
      end

      def report_highlighted_area(highlighted_area)
        space_area  = highlighted_area.source_buffer.slice(0...highlighted_area.begin_pos)
        source_area = highlighted_area.source
        output.puts("#{' ' * Unicode::DisplayWidth.of(space_area)}" \
                    "#{'^' * Unicode::DisplayWidth.of(source_area)}")
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 4 rubygems

Version Path
rubocop-1.70.0 lib/rubocop/formatter/clang_style_formatter.rb
minato_ruby_api_client-0.2.2 vendor/bundle/ruby/3.2.0/gems/rubocop-1.64.1/lib/rubocop/formatter/clang_style_formatter.rb
rubocop-1.69.2 lib/rubocop/formatter/clang_style_formatter.rb
rubocop-1.69.1 lib/rubocop/formatter/clang_style_formatter.rb
rubocop-1.69.0 lib/rubocop/formatter/clang_style_formatter.rb
rubocop-1.68.0 lib/rubocop/formatter/clang_style_formatter.rb
rubocop-1.67.0 lib/rubocop/formatter/clang_style_formatter.rb
rubocop-1.66.1 lib/rubocop/formatter/clang_style_formatter.rb
rubocop-1.66.0 lib/rubocop/formatter/clang_style_formatter.rb
rubocop-1.65.1 lib/rubocop/formatter/clang_style_formatter.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/rubocop-1.64.1/lib/rubocop/formatter/clang_style_formatter.rb
rubocop-1.65.0 lib/rubocop/formatter/clang_style_formatter.rb
katalyst-govuk-formbuilder-1.9.2 vendor/bundle/ruby/3.3.0/gems/rubocop-1.64.1/lib/rubocop/formatter/clang_style_formatter.rb
rubocop-1.64.1 lib/rubocop/formatter/clang_style_formatter.rb
rubocop-1.63.4 lib/rubocop/formatter/clang_style_formatter.rb
rubocop-1.63.3 lib/rubocop/formatter/clang_style_formatter.rb
rubocop-1.63.2 lib/rubocop/formatter/clang_style_formatter.rb
rubocop-1.63.1 lib/rubocop/formatter/clang_style_formatter.rb
rubocop-1.63.0 lib/rubocop/formatter/clang_style_formatter.rb