Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
61 lines (47 sloc) 1.43 KB
wrapper for JSLint
reformats output (<filename>:<line>:<column>:<message>)
allows specifying JSLint options via the command line
$ <filename> [options]
options is a collection of individual "<key>:<value>" arguments
import sys
import subprocess
import re
# settings -- TODO: read from configuration file
cmd = "rhino"
lint = "/home/fnd/Scripts/JSLint/jslint.js"
pattern = r"Lint at line (\d+) character (\d+): (.*)"
tempFile = "/tmp/jslint_wrap"
def main(args):
original = filename = args[1] # original filename might differ from actually linted file
options = args[2:]
if options:
filename = setOptions(filename, options)
command = [cmd, lint, filename]
output = subprocess.Popen(command, stdout=subprocess.PIPE).communicate()[0]
print "\n".join(reformat(output, pattern, original))
return True
def reformat(text, pattern, filename):
results = []
regex = re.compile(pattern)
for line in text.split("\n"):
matches =
if matches:
line = int(matches.groups()[0])
char = int(matches.groups()[1])
msg = matches.groups()[2]
results.append("%s:%d:%d:%s" % (filename, line, char, msg))
return results
def setOptions(filename, options):
f = open(filename, "r")
contents = "/*jslint %s */ %s" % (" ".join(options),
f = open(tempFile, "w")
return tempFile
if __name__ == "__main__":
status = not main(sys.argv)
Something went wrong with that request. Please try again.