Class: JavascriptLintParser

Inherits:
Object
  • Object
show all
Defined in:
lib/tasks/javascript_lint/javascript_lint_parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(dir) ⇒ JavascriptLintParser

Returns a new instance of JavascriptLintParser.



3
4
5
6
7
8
9
10
# File 'lib/tasks/javascript_lint/javascript_lint_parser.rb', line 3

def initialize(dir)
  @dir = dir
 
  # TODO: Tidy!
  if (RUBY_PLATFORM =~ /mswin32/)
    @dir = @dir.gsub('/', '\\')
  end 
end

Instance Method Details

#parse_result(detail) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/tasks/javascript_lint/javascript_lint_parser.rb', line 12

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

#strip_dir(text) ⇒ Object



42
43
44
45
46
47
48
49
# File 'lib/tasks/javascript_lint/javascript_lint_parser.rb', line 42

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