Module: JSHint::Utils
- Defined in:
- lib/jshint/utils.rb
Class Method Summary collapse
- .copy_config_file ⇒ Object
-
.exclude_files(list, excluded) ⇒ Object
workaround for a problem with case-insensitive file systems like HFS on Mac.
- .load_config_file(file_name) ⇒ Object
- .path_from_command_line(field) ⇒ Object
- .paths_from_command_line(field) ⇒ Object
- .remove_config_file ⇒ Object
-
.unique_files(list) ⇒ Object
workaround for a problem with case-insensitive file systems like HFS on Mac.
- .xprint(txt) ⇒ Object
- .xputs(txt) ⇒ Object
Class Method Details
.copy_config_file ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/jshint/utils.rb', line 55 def copy_config_file raise ArgumentError, "Please set JSHint.config_path" if JSHint.config_path.nil? xprint "Creating example JSHint config file in #{File.(JSHint.config_path)}... " if File.exists?(JSHint.config_path) xputs "\n\nWarning: config file exists, so it won't be overwritten. " + "You can copy it manually from the jshint_on_rails directory if you want to reset it." else FileUtils.copy(JSHint::DEFAULT_CONFIG_FILE, JSHint.config_path) xputs "done." end end |
.exclude_files(list, excluded) ⇒ Object
workaround for a problem with case-insensitive file systems like HFS on Mac
42 43 44 |
# File 'lib/jshint/utils.rb', line 42 def exclude_files(list, excluded) list.reject { |entry| excluded.any? { |f| File.identical?(f, entry) }} end |
.load_config_file(file_name) ⇒ Object
24 25 26 27 28 29 30 |
# File 'lib/jshint/utils.rb', line 24 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 |
.path_from_command_line(field) ⇒ Object
46 47 48 |
# File 'lib/jshint/utils.rb', line 46 def path_from_command_line(field) ENV[field] || ENV[field.upcase] end |
.paths_from_command_line(field) ⇒ Object
50 51 52 53 |
# File 'lib/jshint/utils.rb', line 50 def paths_from_command_line(field) argument = ENV[field] || ENV[field.upcase] argument && argument.split(/,/) end |
.remove_config_file ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/jshint/utils.rb', line 67 def remove_config_file raise ArgumentError, "Please set JSHint.config_path" if JSHint.config_path.nil? xprint "Removing config file... " if File.exists?(JSHint.config_path) && File.file?(JSHint.config_path) if File.read(JSHint.config_path) == File.read(JSHint::DEFAULT_CONFIG_FILE) File.delete(JSHint.config_path) xputs "OK." else xputs "File was modified, so it won't be deleted automatically." end else xputs "OK (no config file found)." end end |
.unique_files(list) ⇒ Object
workaround for a problem with case-insensitive file systems like HFS on Mac
33 34 35 36 37 38 39 |
# File 'lib/jshint/utils.rb', line 33 def unique_files(list) files = [] list.each do |entry| files << entry unless files.any? { |f| File.identical?(f, entry) } end files end |
.xprint(txt) ⇒ Object
16 17 18 |
# File 'lib/jshint/utils.rb', line 16 def xprint(txt) print txt end |
.xputs(txt) ⇒ Object
20 21 22 |
# File 'lib/jshint/utils.rb', line 20 def xputs(txt) puts txt end |