Skip to content

Instantly share code, notes, and snippets.

@jjulian
Created July 30, 2009 02:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jjulian/158504 to your computer and use it in GitHub Desktop.
Save jjulian/158504 to your computer and use it in GitHub Desktop.
desc "Check the JavaScript source with JSLint - exit with status 1 if any of the files fail."
task :jslint do
failed_files = []
classpath = File.join(RAILS_ROOT, "vendor", "rhino.jar")
jslint_path = File.join(RAILS_ROOT, "vendor", "jslint.js")
Dir['public/**/*.js'].reject{|path| path =~ /public\/ext\//}.each do |fname|
cmd = "java -cp #{classpath} org.mozilla.javascript.tools.shell.Main #{jslint_path} #{fname}"
results = %x{#{cmd}}
unless results =~ /^jslint: No problems found in/
puts "#{fname}:"
puts results
failed_files << fname
end
end
if failed_files.size > 0
exit 1
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment