Module: JSLint::Utils

Defined in:
lib/jslint/utils.rb

Class Method Summary collapse

Class Method Details

.copy_config_fileObject



66
67
68
69
70
71
72
73
74
75
# File 'lib/jslint/utils.rb', line 66

def copy_config_file
  display "Creating example JSLint config file in #{File.expand_path(JSLint.config_path)}... "
  if File.exists?(JSLint.config_path)
    log "\n\nWarning: config file exists, so it won't be overwritten. " +
        "You can copy it manually from the jslint_on_rails directory if you want to reset it."
  else
    FileUtils.copy(JSLint::DEFAULT_CONFIG_FILE, JSLint.config_path)
    log "done."
  end
end

.default_config_pathObject



23
24
25
26
27
28
29
# File 'lib/jslint/utils.rb', line 23

def default_config_path
  if in_rails?
    File.expand_path(File.join(Rails.root, 'config', 'jslint.yml'))
  else
    'config/jslint.yml'
  end
end

.display(txt) ⇒ Object



31
32
33
# File 'lib/jslint/utils.rb', line 31

def display(txt)
  print txt
end

.exclude_files(list, excluded) ⇒ Object

workaround for a problem with case-insensitive file systems like HFS on Mac



57
58
59
# File 'lib/jslint/utils.rb', line 57

def exclude_files(list, excluded)
  list.reject { |entry| excluded.any? { |f| File.identical?(f, entry) }}
end

.in_rails?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/jslint/utils.rb', line 19

def in_rails?
  defined?(Rails)
end

.load_config_file(file_name) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/jslint/utils.rb', line 39

def load_config_file(file_name)
  if file_name && File.exists?(file_name) && File.file?(file_name) && File.readable?(file_name)
    YAML.load_file(file_name)
  else
    {}
  end
end

.log(txt) ⇒ Object



35
36
37
# File 'lib/jslint/utils.rb', line 35

def log(txt)
  puts txt
end

.paths_from_command_line(field) ⇒ Object



61
62
63
64
# File 'lib/jslint/utils.rb', line 61

def paths_from_command_line(field)
  argument = ENV[field] || ENV[field.upcase]
  argument && argument.split(/,/)
end

.unique_files(list) ⇒ Object

workaround for a problem with case-insensitive file systems like HFS on Mac



48
49
50
51
52
53
54
# File 'lib/jslint/utils.rb', line 48

def unique_files(list)
  files = []
  list.each do |entry|
    files << entry unless files.any? { |f| File.identical?(f, entry) }
  end
  files
end