Class: JslintRb::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/jslint-rb/runner.rb

Overview

This class uses ExecJS to execute the JSHINT function with the config options provided. Uses MultiJson to dump the Ruby objects to well formatted JS.

Instance Method Summary collapse

Constructor Details

#initialize(filename, options) ⇒ Runner

Returns a new instance of Runner.



10
11
12
13
# File 'lib/jslint-rb/runner.rb', line 10

def initialize(filename, options)
  @filename = filename
  @config = options
end

Instance Method Details

#executeObject

Executes JSHint, with the options and globals provided. Converts the JS output to an array of JslintRb::Error objects



18
19
20
21
22
23
24
25
# File 'lib/jslint-rb/runner.rb', line 18

def execute
  context = ExecJS.compile(File.read(@config[:lint_location]))
  output = context.exec("JSHINT(#{MultiJson.dump(File.read(@filename))},"\
                        "#{MultiJson.dump(@config[:lint_options])},"\
                        "#{MultiJson.dump(@config[:global_vars])});"\
                        "return JSHINT.errors")
  output.compact.map {|x| JslintRb::Error.new(x) }
end