tools/linelength.py

Fri, 03 Mar 2017 23:08:04 +0200

author
Teemu Piippo <teemu@hecknology.net>
date
Fri, 03 Mar 2017 23:08:04 +0200
changeset 1178
3a88e7a60b63
parent 1058
695edd4f0411
permissions
-rwxr-xr-x

At long last, the grid is finally now rendered onto the viewport. Woop!

#!/usr/bin/env python3
from sys import argv, stderr
from os.path import realpath

for filename in argv[1:]:
	with open(filename, 'r') as fp:
		try:
			exceeders = [(i + 1) for i, ln in enumerate(fp.read().splitlines()) if len(ln.replace('\t', '    ')) > 140]

			for linenumber in exceeders:
				stderr.write('%s:%d: warning: line length exceeds 120 characters\n' % (realpath(filename), linenumber))
		except Exception as e:
			stderr.write('%s: warning: %s: %s\n' % (realpath(filename), type(e).__name__, e))

mercurial