Skip to content

Instantly share code, notes, and snippets.

@davidcornu
Created May 4, 2011 03:42
Show Gist options
  • Save davidcornu/954719 to your computer and use it in GitHub Desktop.
Save davidcornu/954719 to your computer and use it in GitHub Desktop.
Textmate JSLint
#!/usr/bin/env ruby
require 'cgi'
lint = `/usr/local/bin/jslint4java #{ENV['TM_FILEPATH']}`
lrxp = Regexp.new(/jslint:.+.js:(\d+):(\d+):(.+)/i)
output = String.new
lint.split("\n").each do |error|
match = lrxp.match(error)
line = `cat #{ENV['TM_FILEPATH']} | head -#{match[1]} | tail -1`
output << "<p><a href='txmt://open?url=file://#{ENV['TM_FILEPATH']}&line=#{match[1]}'><b>Error at Line #{match[1]} Character #{match[2]}:</b></a> #{match[3]}</p><pre>#{CGI.escapeHTML(line).lstrip}</pre>"
end
print <<HTML
<!DOCTYPE html>
<html>
<head>
<style>
pre{
border: 1px solid #cecece;
background: #eee;
font-size: 12px;
padding: 2px 4px;
}
p > a{
text-decoration: none;
color: black;
}
p > a:hover{
text-decoration: underline;
}
</style>
</head>
<body>
#{output}
</body>
</html>
HTML
@davidcornu
Copy link
Author

Requires:
brew install jslint4java

Input: Entire File
Output: HTML

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment