Class: JSLint

Inherits:
Object
  • Object
show all
Defined in:
lib/js_lint.rb

Instance Method Summary collapse

Constructor Details

#initialize(source) ⇒ JSLint

Returns a new instance of JSLint.



6
7
8
9
10
11
12
# File 'lib/js_lint.rb', line 6

def initialize source
  @source = source
  @context = V8::Context.new
  load("fulljslint")
  load("options")       #TODO: refactor options to be a param
  load("json2")
end

Instance Method Details

#load(filename) ⇒ Object



25
26
27
# File 'lib/js_lint.rb', line 25

def load filename
  @context.load(File.join(File.dirname(__FILE__),"#{filename}.js"))
end

#treeObject



14
15
16
17
18
19
20
21
22
23
# File 'lib/js_lint.rb', line 14

def tree
  @context['source'] = @source

  code = <<Code
    JSLINT(source.toString(), options);
    JSON.stringify(JSLINT.tree, ['value',  'arity', 'name',  'first', 'second', 'third', 'block', 'else'], 4);
Code

  JSON.parse(@context.eval_js(code), :max_nesting => 100)
end