Skip to content

Instantly share code, notes, and snippets.

@lukaszkorecki
Forked from jjulian/jslint rake task
Created March 2, 2010 14:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lukaszkorecki/319556 to your computer and use it in GitHub Desktop.
Save lukaszkorecki/319556 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
jsl_path = "jsl" # get jsl bin from http://javascriptlint.com
failed_files = []
Dir['public/**/*.js'].reject{|path| path =~ /javascripts.js/ }.each do |fname|
cmd = "#{jsl_path} -nologo -nocontext -nofilelisting -process #{fname} | grep err"
results = %x{#{cmd}}
puts "#{fname} | " << results
results.gsub("(s)","").split(",").each do |result|
result = result.split(" ")
if result[0].to_i > 0 and result[1] =~ /error/
failed_files << fname
end
end
end
puts "="*80
if failed_files.size > 0
failed_files.each { |file| puts "[ERROR] " << file }
exit 1
else
puts "No problems"
end
end
#!/usr/bin/env bash
rake assets:jslint
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment