Class: JSHint::Lint
- Inherits:
-
Object
- Object
- JSHint::Lint
- Defined in:
- lib/jshint/lint.rb
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Lint
constructor
available options: :paths => [list of paths…] :exclude_paths => [list of exluded paths…] :config_path => path to custom config file (can be set via JSHint.config_path too).
- #run ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Lint
available options: :paths => [list of paths…] :exclude_paths => [list of exluded paths…] :config_path => path to custom config file (can be set via JSHint.config_path too)
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/jshint/lint.rb', line 18 def initialize( = {}) default_config = Utils.load_config_file(DEFAULT_CONFIG_FILE) custom_config = Utils.load_config_file([:config_path] || JSHint.config_path) @config = default_config.merge(custom_config) if @config['predef'] @config['predef'] = @config['predef'].split(",") unless @config['predef'].is_a?(Array) end included_files = files_matching_paths(, :paths) excluded_files = files_matching_paths(, :exclude_paths) @file_list = Utils.exclude_files(included_files, excluded_files) @file_list.delete_if { |f| File.size(f) == 0 } ['paths', 'exclude_paths'].each { |field| @config.delete(field) } end |
Instance Method Details
#run ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/jshint/lint.rb', line 34 def run raise NoEngineException, "No JS engine available" unless js_engine Utils.log "Running JSHint via #{js_engine.name}:\n\n" errors = @file_list.map { |file| process_file(file) }.flatten if errors.length == 0 Utils.log "\nNo JS errors found." else Utils.log "\nFound #{Utils.pluralize(errors.length, 'error')}." raise LintCheckFailure, "JSHint test failed." end end |