2016-01-06 22:47:14 +03:00
|
|
|
#!/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.
|
2016-05-13 00:10:39 +03:00
|
|
|
|
2016-05-13 00:11:35 +03:00
|
|
|
from __future__ import absolute_import, print_function
|
2016-05-13 00:10:39 +03:00
|
|
|
|
2016-01-06 22:47:14 +03:00
|
|
|
import re
|
2016-05-13 00:10:39 +03:00
|
|
|
import sys
|
2016-01-06 22:47:14 +03:00
|
|
|
|
|
|
|
leadingline = re.compile(r'(^\s*)(\S.*)$')
|
2016-03-03 06:32:44 +03:00
|
|
|
|
|
|
|
checks = [
|
|
|
|
(r""":hg:`[^`]*'[^`]*`""",
|
|
|
|
"""warning: please avoid nesting ' in :hg:`...`"""),
|
|
|
|
(r'\w:hg:`',
|
|
|
|
'warning: please have a space before :hg:'),
|
2016-01-12 12:30:57 +03:00
|
|
|
(r"""(?:[^a-z][^'.])hg ([^,;"`]*'(?!hg)){2}""",
|
|
|
|
'''warning: please use " instead of ' for hg ... "..."'''),
|
2016-03-03 06:32:44 +03:00
|
|
|
]
|
2016-01-06 22:47:14 +03:00
|
|
|
|
2018-01-09 14:44:33 +03:00
|
|
|
# The below needed because of how we try to figure out the hg 'arg' pattern. If
|
|
|
|
# there exists a message like "word hg word d'aide word word d'aide", this
|
|
|
|
# checker will break. The proper fix would be to identify command line examples
|
|
|
|
# better, but it is hard to do.
|
|
|
|
# ("d'aide" is present a lot in a generated docs since it's a part of
|
|
|
|
# "pas d'aide disponible", French for "no help available")
|
|
|
|
exception_words = ["d'aide"]
|
|
|
|
|
2016-01-06 22:47:14 +03:00
|
|
|
def check(line):
|
2016-03-03 06:32:44 +03:00
|
|
|
messages = []
|
|
|
|
for match, msg in checks:
|
2018-01-09 14:44:33 +03:00
|
|
|
m = re.search(match, line)
|
|
|
|
if m:
|
|
|
|
for ew in exception_words:
|
|
|
|
if ew in m.group():
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
messages.append(msg)
|
2016-03-03 06:32:44 +03:00
|
|
|
if messages:
|
2016-02-10 16:44:29 +03:00
|
|
|
print(line)
|
2016-03-03 06:32:44 +03:00
|
|
|
for msg in messages:
|
|
|
|
print(msg)
|
2016-01-06 22:47:14 +03:00
|
|
|
|
|
|
|
def work(file):
|
2016-02-10 16:44:29 +03:00
|
|
|
(llead, lline) = ('', '')
|
2016-01-06 22:47:14 +03:00
|
|
|
|
2016-02-10 16:44:29 +03:00
|
|
|
for line in file:
|
|
|
|
# this section unwraps lines
|
|
|
|
match = leadingline.match(line)
|
|
|
|
if not match:
|
|
|
|
check(lline)
|
|
|
|
(llead, lline) = ('', '')
|
|
|
|
continue
|
2016-01-06 22:47:14 +03:00
|
|
|
|
2016-02-10 16:44:29 +03:00
|
|
|
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)
|
2016-01-06 22:47:14 +03:00
|
|
|
|
|
|
|
def main():
|
2016-02-10 16:44:29 +03:00
|
|
|
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))
|
2016-01-06 22:47:14 +03:00
|
|
|
|
|
|
|
main()
|