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