docchecker
63 lines
| 1.6 KiB
| text/plain
|
TextLexer
/ doc / docchecker
|
r27730 | #!/usr/bin/env python | ||
# | ||||
# docchecker - look for problematic markup | ||||
# | ||||
# Copyright 2016 timeless <timeless@mozdev.org> and others | ||||
# | ||||
# This software may be used and distributed according to the terms of the | ||||
# GNU General Public License version 2 or any later version. | ||||
import sys | ||||
import re | ||||
leadingline = re.compile(r'(^\s*)(\S.*)$') | ||||
|
r28810 | |||
checks = [ | ||||
(r""":hg:`[^`]*'[^`]*`""", | ||||
"""warning: please avoid nesting ' in :hg:`...`"""), | ||||
(r'\w:hg:`', | ||||
'warning: please have a space before :hg:'), | ||||
|
r28811 | (r"""(?:[^a-z][^'.])hg ([^,;"`]*'(?!hg)){2}""", | ||
'''warning: please use " instead of ' for hg ... "..."'''), | ||||
|
r28810 | ] | ||
|
r27730 | |||
def check(line): | ||||
|
r28810 | messages = [] | ||
for match, msg in checks: | ||||
if re.search(match, line): | ||||
messages.append(msg) | ||||
if messages: | ||||
|
r28049 | print(line) | ||
|
r28810 | for msg in messages: | ||
print(msg) | ||||
|
r27730 | |||
def work(file): | ||||
|
r28049 | (llead, lline) = ('', '') | ||
|
r27730 | |||
|
r28049 | for line in file: | ||
# this section unwraps lines | ||||
match = leadingline.match(line) | ||||
if not match: | ||||
check(lline) | ||||
(llead, lline) = ('', '') | ||||
continue | ||||
|
r27730 | |||
|
r28049 | lead, line = match.group(1), match.group(2) | ||
if (lead == llead): | ||||
if (lline != ''): | ||||
lline += ' ' + line | ||||
else: | ||||
lline = line | ||||
else: | ||||
check(lline) | ||||
(llead, lline) = (lead, line) | ||||
check(lline) | ||||
|
r27730 | |||
def main(): | ||||
|
r28049 | for f in sys.argv[1:]: | ||
try: | ||||
with open(f) as file: | ||||
work(file) | ||||
except BaseException as e: | ||||
print("failed to process %s: %s" % (f, e)) | ||||
|
r27730 | |||
main() | ||||