##// END OF EJS Templates
docchecker: try to reject single quotes
timeless -
r28811:1a623585 default
parent child Browse files
Show More
@@ -1,61 +1,63 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 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
13
14 checks = [
14 checks = [
15 (r""":hg:`[^`]*'[^`]*`""",
15 (r""":hg:`[^`]*'[^`]*`""",
16 """warning: please avoid nesting ' in :hg:`...`"""),
16 """warning: please avoid nesting ' in :hg:`...`"""),
17 (r'\w:hg:`',
17 (r'\w:hg:`',
18 'warning: please have a space before :hg:'),
18 'warning: please have a space before :hg:'),
19 (r"""(?:[^a-z][^'.])hg ([^,;"`]*'(?!hg)){2}""",
20 '''warning: please use " instead of ' for hg ... "..."'''),
19 ]
21 ]
20
22
21 def check(line):
23 def check(line):
22 messages = []
24 messages = []
23 for match, msg in checks:
25 for match, msg in checks:
24 if re.search(match, line):
26 if re.search(match, line):
25 messages.append(msg)
27 messages.append(msg)
26 if messages:
28 if messages:
27 print(line)
29 print(line)
28 for msg in messages:
30 for msg in messages:
29 print(msg)
31 print(msg)
30
32
31 def work(file):
33 def work(file):
32 (llead, lline) = ('', '')
34 (llead, lline) = ('', '')
33
35
34 for line in file:
36 for line in file:
35 # this section unwraps lines
37 # this section unwraps lines
36 match = leadingline.match(line)
38 match = leadingline.match(line)
37 if not match:
39 if not match:
38 check(lline)
40 check(lline)
39 (llead, lline) = ('', '')
41 (llead, lline) = ('', '')
40 continue
42 continue
41
43
42 lead, line = match.group(1), match.group(2)
44 lead, line = match.group(1), match.group(2)
43 if (lead == llead):
45 if (lead == llead):
44 if (lline != ''):
46 if (lline != ''):
45 lline += ' ' + line
47 lline += ' ' + line
46 else:
48 else:
47 lline = line
49 lline = line
48 else:
50 else:
49 check(lline)
51 check(lline)
50 (llead, lline) = (lead, line)
52 (llead, lline) = (lead, line)
51 check(lline)
53 check(lline)
52
54
53 def main():
55 def main():
54 for f in sys.argv[1:]:
56 for f in sys.argv[1:]:
55 try:
57 try:
56 with open(f) as file:
58 with open(f) as file:
57 work(file)
59 work(file)
58 except BaseException as e:
60 except BaseException as e:
59 print("failed to process %s: %s" % (f, e))
61 print("failed to process %s: %s" % (f, e))
60
62
61 main()
63 main()
@@ -1,4 +1,6 b''
1 #require docutils gettext
1 #require docutils gettext
2
2
3 $ $TESTDIR/check-gendoc ja
3 $ $TESTDIR/check-gendoc ja
4 checking for parse errors
4 checking for parse errors
5 \xe8\xa4\x87\xe8\xa3\xbd\xef\xbc\x8f\xe6\x94\xb9\xe5\x90\x8d\xe3\x81\xab\xe9\x96\xa2\xe3\x81\x99\xe3\x82\x8b\xe5\xb1\xa5\xe6\xad\xb4\xe4\xbf\x9d\xe5\xad\x98\xe3\x81\xae\xe3\x81\x9f\xe3\x82\x81\xe3\x81\xab git \xe5\xb7\xae\xe5\x88\x86\xe5\xbd\xa2\xe5\xbc\x8f\xe3\x82\x92\xe4\xbd\xbf\xe7\x94\xa8(-g/--git \xe6\x8c\x87\xe5\xae\x9a\xe3\x82\x84 \xe8\xa8\xad\xe5\xae\x9a\xe3\x83\x95\xe3\x82\xa1\xe3\x82\xa4\xe3\x83\xab\xe3\x81\xa7\xe3\x81\xae [diff] git=1 \xe8\xa8\x98\xe8\xbf\xb0)\xe3\x81\x99\xe3\x82\x8b\xe3\x81\xae\xe3\x81\xa7\xe3\x81\x82\xe3\x82\x8c\xe3\x81\xb0\xe3\x80\x81 add/remove/copy/rename \xe3\x81\xa8\xe3\x81\x84\xe3\x81\xa3\xe3\x81\x9f hg \xe3\x81\xae\xe3\x82\xb3\xe3\x83\x9e\xe3\x83\xb3\xe3\x83\x89\xe3\x81\xab\xe3\x82\x88\xe3\x82\x8b\xe5\xb1\xa5\xe6\xad\xb4\xe8\xa8\x98\xe9\x8c\xb2\xe3\x82\x82\xe3\x80\x81 \xe9\x80\x9a\xe5\xb8\xb8\xe3\x81\xa8\xe5\xa4\x89\xe3\x82\x8f\xe3\x82\x8a\xe3\x81\xaa\xe3\x81\x8f\xe6\xa9\x9f\xe8\x83\xbd\xe3\x81\x97\xe3\x81\xbe\xe3\x81\x99\xe3\x80\x82 git \xe5\xb7\xae\xe5\x88\x86\xe5\xbd\xa2\xe5\xbc\x8f\xe3\x81\xae\xe8\xa9\xb3\xe7\xb4\xb0\xe3\x81\xab\xe9\x96\xa2\xe3\x81\x97\xe3\x81\xa6\xe3\x81\xaf\xe3\x80\x81 'help diffs' \xe3\x82\x92\xe5\x8f\x82\xe7\x85\xa7\xe3\x81\x97\xe3\x81\xa6\xe3\x81\x8f\xe3\x81\xa0\xe3\x81\x95\xe3\x81\x84\xe3\x80\x82 (esc)
6 warning: please use " instead of ' for hg ... "..."
General Comments 0
You need to be logged in to leave comments. Login now