Class: Distil::ValidateJsTask

Inherits:
Task show all
Includes:
ErrorReporter
Defined in:
lib/distil/task/validate-js-task.rb

Overview

LINT_COMMAND= “/Users/jeff/.gem/ruby/1.8/gems/distil-0.10.2/vendor/jsl-0.3.0/bin/jsl”

Instance Attribute Summary

Attributes inherited from Configurable

#options

Instance Method Summary collapse

Methods included from ErrorReporter

#error, error, #ignore_warnings, #ignore_warnings=, #report, warning, #warning

Methods inherited from Task

#find_files, #handles_file?, #include_file, inherited, #initialize, #project, #target, tasks

Methods inherited from Configurable

#get_option, #get_options, #initialize, option

Constructor Details

This class inherits a constructor from Distil::Task

Instance Method Details

#handles_file(file) ⇒ Object



14
15
16
# File 'lib/distil/task/validate-js-task.rb', line 14

def handles_file(file)
  return ["js"].include?(file.content_type)
end

#process_files(files) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/distil/task/validate-js-task.rb', line 18

def process_files(files)
  return if (!File.exists?(LINT_COMMAND))

  tmp= Tempfile.new("jsl.conf")

  conf_files= [ "jsl.conf",
                "#{ENV['HOME']}/.jsl.conf",
                jsl_conf
              ]

  jsl_conf= conf_files.find { |f| File.exists?(f) }

  tmp << File.read(jsl_conf)
  tmp << "\n"

  tmp << "+define distil\n"
  
  if (global_export)
    tmp << "+define #{global_export}\n"
  end
  
  # additional_globals.each { |g|
  #   tmp << "+define #{g}\n"
  # }
  
  target.file_aliases.each { |original, full_path|
    next if !File.exist?(full_path)
    tmp << "+alias #{original} #{full_path}\n"
  }
  
  files.each { |f|
    next if !handles_file(f)
    tmp << "+process #{f}\n"
  }

  tmp.close()
  command= "#{LINT_COMMAND} -nologo -nofilelisting -conf #{tmp.path}"

  stdin, stdout, stderr= Open3.popen3(command)
  stdin.close
  output= stdout.read
  errors= stderr.read

  tmp.delete

  output= output.split("\n")
  summary= output.pop
  match= summary.match(/(\d+)\s+error\(s\), (\d+)\s+warning\(s\)/)
  if (match)
      @@error_count+= match[1].to_i
      @@warning_count+= match[2].to_i
  end

  output= output.join("\n")

  if (!output.empty?)
      puts output
      puts
  end

end