Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: ddcd0495d4
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 61 lines (47 sloc) 1.463 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
"""
wrapper for JSLint

reformats output (<filename>:<line>:<column>:<message>)
allows specifying JSLint options via the command line

Usage:
$ wrapper.py <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 = regex.search(line)
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.read())
f.close()
f = open(tempFile, "w")
f.write(contents)
f.close()
return tempFile


if __name__ == "__main__":
status = not main(sys.argv)
sys.exit(status)
Something went wrong with that request. Please try again.