Class: Jshint::Configuration

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

Overview

Configuration object containing JSHint lint settings

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path = nil) ⇒ Configuration

Initializes our configuration object

Parameters:

  • path (String) (defaults to: nil)

    The path to the config file



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

def initialize(path = nil)
  @path = path || default_config_path
  @options = parse_yaml_config
end

Instance Attribute Details

#optionsHash (readonly)

Returns the configration options.

Returns:

  • (Hash)

    the configration options



8
9
10
# File 'lib/jshint/configuration.rb', line 8

def options
  @options
end

Instance Method Details

#[](key) ⇒ Object

Returns the value of the options Hash if one exists

Parameters:

  • key (Symbol)

Returns:

  • The value of the of the options Hash at the passed in key



22
23
24
# File 'lib/jshint/configuration.rb', line 22

def [](key)
  options["options"][key.to_s]
end

#default_search_pathsObject



79
80
81
82
83
84
85
# File 'lib/jshint/configuration.rb', line 79

def default_search_paths
  [
    'app/assets/javascripts',
    'vendor/assets/javascripts',
    'lib/assets/javascripts'
  ]
end

#excluded_search_pathsObject



67
68
69
# File 'lib/jshint/configuration.rb', line 67

def excluded_search_paths
  options.fetch("exclude_paths", [])
end

#filesArray<String>

Returns the list of files that JSHint should lint over relatives to the Application root

Examples:

[
  'angular/controllers/*.js',
  'angular/services/*.js'
]

Returns:

  • (Array<String>)

    An Array of String files paths



63
64
65
# File 'lib/jshint/configuration.rb', line 63

def files
  options["files"]
end

#global_variablesHash?

Returns a Hash of global variables if one exists

Examples:

{
  "$" => true,
  jQuery => true,
  angular => true
}

Returns:

  • (Hash, nil)

    The key value pairs or nil



36
37
38
# File 'lib/jshint/configuration.rb', line 36

def global_variables
  options["options"]["globals"]
end

#included_search_pathsObject



71
72
73
# File 'lib/jshint/configuration.rb', line 71

def included_search_paths
  options.fetch("include_paths", [])
end

#lint_optionsHash?

Returns a Hash of options to be used by JSHint

See jshint.com/docs/options/ for more config options

Examples:

{
  "eqeqeq" => true,
  "indent" => 2
}

Returns:

  • (Hash, nil)

    The key value pairs of options or nil



50
51
52
# File 'lib/jshint/configuration.rb', line 50

def lint_options
  @lint_options ||= options["options"].reject { |key| key == "globals" }
end

#search_pathsObject



75
76
77
# File 'lib/jshint/configuration.rb', line 75

def search_paths
  (default_search_paths + included_search_paths) - excluded_search_paths
end