Class: Redcar::SyntaxCheck::JavaScript

Inherits:
Checker
  • Object
show all
Defined in:
lib/syntax_check/javascript.rb

Instance Method Summary collapse

Instance Method Details

#check(*args) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/syntax_check/javascript.rb', line 20

def check(*args)
  path = manifest_path(doc)
  name = File.basename(path)
  if t = JavaScript.thread and t.alive?
    if t[:doc] and t[:doc] == doc
      t.exit
      SyntaxCheck.remove_syntax_error_annotations(doc.edit_view)
    end
  end
  JavaScript.thread=Thread.new do
    SyntaxCheck.remove_syntax_error_annotations(doc.edit_view)
    Thread.current[:doc] = doc
    begin
      output = `java -cp #{rhino_path} #{main_method} #{jslint_path} #{path}`
      output.each_line do |line|
        if line =~ /Lint at line (\d+) character (\d+): (.*)/
          SyntaxCheck::Error.new(doc, $1.to_i-1, $3).annotate
          sleep 1
        end
      end
    rescue Object => e
      SyntaxCheck.message(
      "An error occurred while parsing #{name}: #{e.message}",:error)
    end
  end
end

#jslint_pathObject



8
9
10
# File 'lib/syntax_check/javascript.rb', line 8

def jslint_path
  File.join(File.dirname(__FILE__),'..','..','vendor','jslint.js')
end

#main_methodObject



16
17
18
# File 'lib/syntax_check/javascript.rb', line 16

def main_method
  "org.mozilla.javascript.tools.shell.Main"
end

#rhino_pathObject



12
13
14
# File 'lib/syntax_check/javascript.rb', line 12

def rhino_path
  File.join(File.expand_path('../../../vendor/rhino1_7R3.jar', __FILE__))
end