Skip to content
This repository has been archived by the owner on Dec 18, 2018. It is now read-only.

Commit

Permalink
make output machine readable
Browse files Browse the repository at this point in the history
Using Unix-style line number links and delimitors makes it easier to
parse the output using standard tools.

Specifically, popular editors are able to understand how to navigate
directly to a file's line number, and awk can be used to parse the
different fields.
  • Loading branch information
andreastt committed Nov 5, 2015
1 parent d93ad88 commit b3edcd2
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions lint/lint.py
@@ -1,8 +1,8 @@
import fnmatch
import os
import subprocess
import re
import subprocess
import sys
import fnmatch

from collections import defaultdict

Expand All @@ -24,12 +24,10 @@ def git(command, *args):
except subprocess.CalledProcessError:
raise


def iter_files():
for item in git("ls-tree", "-r", "--name-only", "HEAD").split("\n"):
yield item


def check_path_length(path):
if len(path) + 1 > 150:
return [("PATH LENGTH", "/%s longer than maximum path length (%d > 150)" % (path, len(path) + 1), None)]
Expand Down Expand Up @@ -142,7 +140,7 @@ def check_regexp_line(path, f):
for i, line in enumerate(f):
for regexp in applicable_regexps:
if regexp.search(line):
errors.append((regexp.error, "%s line %i" % (path, i+1), i+1))
errors.append((regexp.error, "%s:%s" % (path, i + 1), i + 1))

return errors

Expand Down Expand Up @@ -173,7 +171,8 @@ def check_parsed(path, f):
errors.append(("MULTIPLE-TESTHARNESS",
"%s more than one <script src='/resources/testharness.js'>" % path, None))

testharnessreport_nodes = source_file.root.findall(".//{http://www.w3.org/1999/xhtml}script[@src='/resources/testharnessreport.js']")
testharnessreport_nodes = source_file.root.findall(
".//{http://www.w3.org/1999/xhtml}script[@src='/resources/testharnessreport.js']")
if not testharnessreport_nodes:
errors.append(("MISSING-TESTHARNESSREPORT",
"%s missing <script src='/resources/testharnessreport.js'>" % path, None))
Expand Down Expand Up @@ -223,7 +222,7 @@ def check_parsed(path, f):

def output_errors(errors):
for error_type, error, line_number in errors:
print "%s: %s" % (error_type, error)
print "%s %s" % (error, error_type)

def output_error_count(error_count):
if not error_count:
Expand All @@ -232,7 +231,7 @@ def output_error_count(error_count):
by_type = " ".join("%s: %d" % item for item in error_count.iteritems())
count = sum(error_count.values())
if count == 1:
print "There was 1 error (%s)" % (by_type,)
print "There was 1 error (%s)" % by_type
else:
print "There were %d errors (%s)" % (count, by_type)

Expand Down

0 comments on commit b3edcd2

Please sign in to comment.