• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python3
2
3import os
4
5ignores = [
6	'.git/',
7	'misc/afl-fuzz-tokens/',
8	'ninja_deps',
9	'src/depfile_parser.cc',
10	'src/lexer.cc',
11]
12
13error_count = 0
14
15def error(path, msg):
16	global error_count
17	error_count += 1
18	print('\x1b[1;31m{}\x1b[0;31m{}\x1b[0m'.format(path, msg))
19
20for root, directory, filenames in os.walk('.'):
21	for filename in filenames:
22		path = os.path.join(root, filename)[2:]
23		if any([path.startswith(x) for x in ignores]):
24			continue
25		with open(path, 'rb') as file:
26			line_nr = 1
27			try:
28				for line in [x.decode() for x in file.readlines()]:
29					if len(line) == 0 or line[-1] != '\n':
30						error(path, ' missing newline at end of file.')
31					if len(line) > 1:
32						if line[-2] == '\r':
33							error(path, ' has Windows line endings.')
34							break
35						if line[-2] == ' ' or line[-2] == '\t':
36							error(path, ':{} has trailing whitespace.'.format(line_nr))
37					line_nr += 1
38			except UnicodeError:
39				pass # binary file
40
41exit(error_count)
42