Class: Jshint::Lint

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

Overview

Performs the linting of the files declared in our Configuration object

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_path = nil) ⇒ void

Sets up our Linting behaviour

Parameters:

  • config_path (String) (defaults to: nil)

    The absolute path to a configuration YAML file



19
20
21
22
# File 'lib/jshint/lint.rb', line 19

def initialize(config_path = nil)
  @config = Configuration.new(config_path)
  @errors = {}
end

Instance Attribute Details

#configJshint::Configuration (readonly)

Returns The configuration object.

Returns:



13
14
15
# File 'lib/jshint/lint.rb', line 13

def config
  @config
end

#errorsHash (readonly)

Returns A Hash of errors.

Returns:

  • (Hash)

    A Hash of errors



10
11
12
# File 'lib/jshint/lint.rb', line 10

def errors
  @errors
end

Instance Method Details

#get_json(hash) ⇒ String

Converts a Hash in to properly escaped JSON

Parameters:

  • hash (Hash)

Returns:

  • (String)

    The JSON outout



42
43
44
# File 'lib/jshint/lint.rb', line 42

def get_json(hash)
  MultiJson.dump(hash)
end

#lintvoid

This method returns an undefined value.

Runs JSHint over each file in our search path



27
28
29
30
31
32
33
34
35
36
# File 'lib/jshint/lint.rb', line 27

def lint
  javascript_files.each do |file|
    file_content = get_file_content_as_json(file)
    code = %(
      JSHINT(#{file_content}, #{jshint_options}, #{jshint_globals});
      return JSHINT.errors;
    )
    errors[file] = context.exec(code)
  end
end