Sha256: 8cc5c3d7d953b4daeae1042f10eee1451c967a539bc3a8b4d1d320dd064886c4

Contents?: true

Size: 1.29 KB

Versions: 8

Compression:

Stored size: 1.29 KB

Contents

# frozen_string_literal: true
module Quality
  # Class processes output from a code quality command, tweaking it
  # for editor output and counting the number of violations found
  class CommandOutputProcessor
    attr_accessor :emacs_format
    attr_accessor :file
    attr_reader :found_output
    attr_reader :violations

    def initialize
      @emacs_format = false
      @found_output = false
      @violations = 0
    end

    def process(&count_violations_on_line)
      process_file(file, &count_violations_on_line)
    end

    private

    def process_file(file, &count_violations_on_line)
      out = ''
      while (@current_line = file.gets)
        out += process_line(&count_violations_on_line)
      end
      out
    end

    def process_line
      output =
        if emacs_format
          preprocess_line_for_emacs
        else
          @current_line
        end
      @found_output = true
      @violations += yield @current_line
      output
    end

    def preprocess_line_for_emacs
      if @current_line =~ /^ *(\S*.rb:[0-9]*) *(.*)/
        Regexp.last_match[1] + ': ' + Regexp.last_match[2] + "\n"
      elsif @current_line =~ /^ *(.*) +(\S*.rb:[0-9]*) *(.*)/
        Regexp.last_match[2] + ': ' + Regexp.last_match[1] + "\n"
      else
        @current_line
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
quality-23.0.7 lib/quality/command_output_processor.rb
quality-23.0.6 lib/quality/command_output_processor.rb
quality-23.0.5 lib/quality/command_output_processor.rb
quality-23.0.4 lib/quality/command_output_processor.rb
quality-23.0.3 lib/quality/command_output_processor.rb
quality-23.0.2 lib/quality/command_output_processor.rb
quality-23.0.1 lib/quality/command_output_processor.rb
quality-23.0.0 lib/quality/command_output_processor.rb