##// END OF EJS Templates
docchecker: report context line at most once
timeless -
r28810:99343629 default
parent child Browse files
Show More
@@ -1,54 +1,61
1 #!/usr/bin/env python
1 #!/usr/bin/env python
2 #
2 #
3 # docchecker - look for problematic markup
3 # docchecker - look for problematic markup
4 #
4 #
5 # Copyright 2016 timeless <timeless@mozdev.org> and others
5 # Copyright 2016 timeless <timeless@mozdev.org> and others
6 #
6 #
7 # This software may be used and distributed according to the terms of the
7 # This software may be used and distributed according to the terms of the
8 # GNU General Public License version 2 or any later version.
8 # GNU General Public License version 2 or any later version.
9 import sys
9 import sys
10 import re
10 import re
11
11
12 leadingline = re.compile(r'(^\s*)(\S.*)$')
12 leadingline = re.compile(r'(^\s*)(\S.*)$')
13 hg_backtick = re.compile(r""":hg:`[^`]*'[^`]*`""")
13
14 hg_cramped = re.compile(r'\w:hg:`')
14 checks = [
15 (r""":hg:`[^`]*'[^`]*`""",
16 """warning: please avoid nesting ' in :hg:`...`"""),
17 (r'\w:hg:`',
18 'warning: please have a space before :hg:'),
19 ]
15
20
16 def check(line):
21 def check(line):
17 if hg_backtick.search(line):
22 messages = []
23 for match, msg in checks:
24 if re.search(match, line):
25 messages.append(msg)
26 if messages:
18 print(line)
27 print(line)
19 print("""warning: please avoid nesting ' in :hg:`...`""")
28 for msg in messages:
20 if hg_cramped.search(line):
29 print(msg)
21 print(line)
22 print('warning: please have a space before :hg:')
23
30
24 def work(file):
31 def work(file):
25 (llead, lline) = ('', '')
32 (llead, lline) = ('', '')
26
33
27 for line in file:
34 for line in file:
28 # this section unwraps lines
35 # this section unwraps lines
29 match = leadingline.match(line)
36 match = leadingline.match(line)
30 if not match:
37 if not match:
31 check(lline)
38 check(lline)
32 (llead, lline) = ('', '')
39 (llead, lline) = ('', '')
33 continue
40 continue
34
41
35 lead, line = match.group(1), match.group(2)
42 lead, line = match.group(1), match.group(2)
36 if (lead == llead):
43 if (lead == llead):
37 if (lline != ''):
44 if (lline != ''):
38 lline += ' ' + line
45 lline += ' ' + line
39 else:
46 else:
40 lline = line
47 lline = line
41 else:
48 else:
42 check(lline)
49 check(lline)
43 (llead, lline) = (lead, line)
50 (llead, lline) = (lead, line)
44 check(lline)
51 check(lline)
45
52
46 def main():
53 def main():
47 for f in sys.argv[1:]:
54 for f in sys.argv[1:]:
48 try:
55 try:
49 with open(f) as file:
56 with open(f) as file:
50 work(file)
57 work(file)
51 except BaseException as e:
58 except BaseException as e:
52 print("failed to process %s: %s" % (f, e))
59 print("failed to process %s: %s" % (f, e))
53
60
54 main()
61 main()
General Comments 0
You need to be logged in to leave comments. Login now