Show More
@@ -1,63 +1,66 b'' | |||||
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 | ||||
|
10 | from __future__ import absolute_import | |||
|
11 | ||||
|
12 | import re | |||
9 | import sys |
|
13 | import sys | |
10 | import re |
|
|||
11 |
|
14 | |||
12 | leadingline = re.compile(r'(^\s*)(\S.*)$') |
|
15 | leadingline = re.compile(r'(^\s*)(\S.*)$') | |
13 |
|
16 | |||
14 | checks = [ |
|
17 | checks = [ | |
15 | (r""":hg:`[^`]*'[^`]*`""", |
|
18 | (r""":hg:`[^`]*'[^`]*`""", | |
16 | """warning: please avoid nesting ' in :hg:`...`"""), |
|
19 | """warning: please avoid nesting ' in :hg:`...`"""), | |
17 | (r'\w:hg:`', |
|
20 | (r'\w:hg:`', | |
18 | 'warning: please have a space before :hg:'), |
|
21 | 'warning: please have a space before :hg:'), | |
19 | (r"""(?:[^a-z][^'.])hg ([^,;"`]*'(?!hg)){2}""", |
|
22 | (r"""(?:[^a-z][^'.])hg ([^,;"`]*'(?!hg)){2}""", | |
20 | '''warning: please use " instead of ' for hg ... "..."'''), |
|
23 | '''warning: please use " instead of ' for hg ... "..."'''), | |
21 | ] |
|
24 | ] | |
22 |
|
25 | |||
23 | def check(line): |
|
26 | def check(line): | |
24 | messages = [] |
|
27 | messages = [] | |
25 | for match, msg in checks: |
|
28 | for match, msg in checks: | |
26 | if re.search(match, line): |
|
29 | if re.search(match, line): | |
27 | messages.append(msg) |
|
30 | messages.append(msg) | |
28 | if messages: |
|
31 | if messages: | |
29 | print(line) |
|
32 | print(line) | |
30 | for msg in messages: |
|
33 | for msg in messages: | |
31 | print(msg) |
|
34 | print(msg) | |
32 |
|
35 | |||
33 | def work(file): |
|
36 | def work(file): | |
34 | (llead, lline) = ('', '') |
|
37 | (llead, lline) = ('', '') | |
35 |
|
38 | |||
36 | for line in file: |
|
39 | for line in file: | |
37 | # this section unwraps lines |
|
40 | # this section unwraps lines | |
38 | match = leadingline.match(line) |
|
41 | match = leadingline.match(line) | |
39 | if not match: |
|
42 | if not match: | |
40 | check(lline) |
|
43 | check(lline) | |
41 | (llead, lline) = ('', '') |
|
44 | (llead, lline) = ('', '') | |
42 | continue |
|
45 | continue | |
43 |
|
46 | |||
44 | lead, line = match.group(1), match.group(2) |
|
47 | lead, line = match.group(1), match.group(2) | |
45 | if (lead == llead): |
|
48 | if (lead == llead): | |
46 | if (lline != ''): |
|
49 | if (lline != ''): | |
47 | lline += ' ' + line |
|
50 | lline += ' ' + line | |
48 | else: |
|
51 | else: | |
49 | lline = line |
|
52 | lline = line | |
50 | else: |
|
53 | else: | |
51 | check(lline) |
|
54 | check(lline) | |
52 | (llead, lline) = (lead, line) |
|
55 | (llead, lline) = (lead, line) | |
53 | check(lline) |
|
56 | check(lline) | |
54 |
|
57 | |||
55 | def main(): |
|
58 | def main(): | |
56 | for f in sys.argv[1:]: |
|
59 | for f in sys.argv[1:]: | |
57 | try: |
|
60 | try: | |
58 | with open(f) as file: |
|
61 | with open(f) as file: | |
59 | work(file) |
|
62 | work(file) | |
60 | except BaseException as e: |
|
63 | except BaseException as e: | |
61 | print("failed to process %s: %s" % (f, e)) |
|
64 | print("failed to process %s: %s" % (f, e)) | |
62 |
|
65 | |||
63 | main() |
|
66 | main() |
General Comments 0
You need to be logged in to leave comments.
Login now