Module: Distil::JavascriptFileValidator

Includes:
ErrorReporter
Included in:
Project
Defined in:
lib/distil/javascript-file-validator.rb

Instance Method Summary collapse

Methods included from ErrorReporter

#error, error, #has_errors?, #has_warnings?, #ignore_warnings, #ignore_warnings=, #report, #total_error_count, #total_warning_count, warning, #warning

Instance Method Details

#validate_javascript_filesObject

Raises:



15
16
17
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
79
80
81
82
83
84
# File 'lib/distil/javascript-file-validator.rb', line 15

def validate_javascript_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|
    next if JS_GLOBALS.include?(g)
    tmp << "+define #{g}\n"
  }
  
  libraries.each { |l|
    tmp.puts "+alias #{l.name} #{l.file_for(:js, nil, DEBUG_VARIANT)}"
  }
  
  dependency_aliases.each { |name, file|
    tmp.puts "+alias #{name} #{file}"
  }
  
  source_files.each { |f|
    tmp.puts "+process #{f}" if f.content_type=="js"
  }

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

  # puts "\n\n\n\n#{name}\n\n"
  # puts "jsl conf:\n#{File.read(tmp.path)}\n\n"
  
  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)
    errors= match[1].to_i
    warnings= match[2].to_i
    @@error_count+= errors
    @@warning_count+= warnings
  end

  output= output.join("\n")

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

  raise BuildFailure if errors>0 # || warnings>0
end