Skip to content

Instantly share code, notes, and snippets.

@robertsosinski
Created January 31, 2010 01:54
Show Gist options
  • Save robertsosinski/290837 to your computer and use it in GitHub Desktop.
Save robertsosinski/290837 to your computer and use it in GitHub Desktop.
JSLint Rake Task
desc "Checks the JavaScript files with JSLint"
task :jslint do
failed_files = []
skipped_files = ["jquery-1.4.js", "jquery-json-2.1.js"]
rhino_path = File.join(RAILS_ROOT, "vendor", "jslint", "js.jar")
jslint_path = File.join(RAILS_ROOT, "vendor", "jslint", "jslint.js")
Dir['public/**/*.js'].reject{|path| skipped_files.include?(path.match(/.*\/(.*)/)[1])}.each do |name|
cmd = "java -jar #{rhino_path} #{jslint_path} #{name}"
results = %x{#{cmd}}
unless results =~ /^jslint: No problems found in/
puts "#{name}:"
puts results
failed_files << name
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