Sha256: 61b4f882d32dec73de900ba5b66dc3a771cf75312131b6def145a032a718d838

Contents?: true

Size: 1.24 KB

Versions: 22

Compression:

Stored size: 1.24 KB

Contents

class JavascriptLintParser
 
  def initialize(dir)
    @dir = dir
 
    # TODO: Tidy!
    if (RUBY_PLATFORM =~ /mswin32/)
      @dir = @dir.gsub('/', '\\')
    end 
  end
  
  def parse_result(detail)
    summary_line = detail.grep( /\d+\s+error.*,\s+\d+\s+warning.*/ )[0]
    
    if summary_line.nil?
      # error
      error_info = (detail + "\nUnknown Error!").to_a[0].strip
      return :error, 'Error', error_info
    end
    
    if summary_line =~ /([1-9]+)\d*\s+error/
      num_failures = $1
      error_info = detail.grep(/\([0-9]+\):([^:]*)Error:/)[0].strip
      return :failure, num_failures + ' Errors', strip_dir(error_info)
    end
 
    if summary_line =~ /([1-9]+)\d*\s+warning/
      num_failures = $1
      error_info = detail.grep(/\([0-9]+\)/)[0].strip
      return :warning, num_failures + ' Warnings', strip_dir(error_info)
    end
    
    # Detect path errors
    path_error = detail.grep(/unable to resolve path/)[0]
    if (!path_error.nil?)
      return :error, 'Path Error', path_error
    end
    
    return :success, 'All files are clean', ''
  end
  
  def strip_dir(text)

    # Move to function/class w/ win32 related code
    if (text[0, @dir.length] == @dir)
      text = text[(@dir.length + 1)..-1]
    end    
    
  end
  
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
loris-0.0.15 lib/tasks/javascript_lint/javascript_lint_parser.rb
loris-0.0.14 lib/tasks/javascript_lint/javascript_lint_parser.rb