File: ci.py

package info (click to toggle)
ninja-build 1.13.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,816 kB
  • sloc: cpp: 21,348; python: 2,473; ansic: 790; sh: 118; makefile: 20
file content (46 lines) | stat: -rwxr-xr-x 1,089 bytes parent folder | download
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
#!/usr/bin/env python3

import os

ignores = [
	'.git/',
	'misc/afl-fuzz-tokens/',
	'src/depfile_parser.cc',
	'src/lexer.cc',
]

error_count = 0

def error(path: str, msg: str) -> None:
	global error_count
	error_count += 1
	print('\x1b[1;31m{}\x1b[0;31m{}\x1b[0m'.format(path, msg))

try:
	import git
	repo = git.Repo('.')
except:
	repo = None

for root, directory, filenames in os.walk('.'):
	for filename in filenames:
		path = os.path.join(root, filename)[2:]
		if any([path.startswith(x) for x in ignores]) or (repo is not None and repo.ignored(path)):
			continue
		with open(path, 'rb') as file:
			line_nr = 1
			try:
				for line in [x.decode() for x in file.readlines()]:
					if len(line) == 0 or line[-1] != '\n':
						error(path, ' missing newline at end of file.')
					if len(line) > 1:
						if line[-2] == '\r':
							error(path, ' has Windows line endings.')
							break
						if line[-2] == ' ' or line[-2] == '\t':
							error(path, ':{} has trailing whitespace.'.format(line_nr))
					line_nr += 1
			except UnicodeError:
				pass # binary file

exit(error_count)