blob: 19d03ec8da2a37d1525cfc8c1388c95d89f05cd5 (
plain)
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
|
#!/usr/bin/python
from __future__ import print_function
from __future__ import with_statement
import sys
import re
import os
def lintfile(fname):
have_warned = []
def warn(s):
if not have_warned:
have_warned.append(1)
print("{}:".format(fname))
print("\t{}".format(s))
m = re.search(r'(\d{3,})', os.path.basename(fname))
if m:
bugnum = m.group(1)
else:
bugnum = None
with open(fname) as f:
contents = f.read()
if bugnum and bugnum not in contents:
warn("bug number {} does not appear".format(bugnum))
lines = contents.split("\n")
isBug = ("bug" in lines[0] or "fix" in lines[0])
if not re.match(r'^ +o (.*)', contents):
warn("header not in format expected")
contents = " ".join(contents.split())
if re.search(r'\#\d{2,}', contents):
warn("don't use a # before ticket numbers")
if isBug and not re.search(r'(\d+)', contents):
warn("bugfix does not mention a number")
elif isBug and not re.search(r'Fixes ([a-z ]*)bug (\d+)', contents):
warn("bugfix does not say 'Fixes bug XXX'")
if re.search(r'[bB]ug (\d+)', contents):
if not re.search(r'[Bb]ugfix on ', contents):
warn("bugfix does not say 'bugfix on X.Y.Z'")
elif not re.search('[fF]ixes ([a-z ]*)bug (\d+); bugfix on ',
contents):
warn("bugfix incant is not semicoloned")
if __name__ == '__main__':
for fname in sys.argv[1:]:
if fname.endswith("~"):
continue
lintfile(fname)
|