Skip to content

Instantly share code, notes, and snippets.

@wallymathieu
Forked from jjulian/jslint rake task
Created August 31, 2011 07:23
Show Gist options
  • Save wallymathieu/1182991 to your computer and use it in GitHub Desktop.
Save wallymathieu/1182991 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