Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/sphinx-doc/sphinx.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2019-05-12 11:57:25 +0300
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2019-05-12 11:57:25 +0300
commit5d2c8e6eb709ca62af18ee570a8682ce1db71b31 (patch)
tree59bd9cfd6ff4b0db2caf4c9d6bf6a27be3f7e860 /utils/doclinter.py
parent935d1ad0af97aefd75bd1883e1ef203d7127101f (diff)
Add utils/doclinter.py; a documenter linter for Sphinx
Diffstat (limited to 'utils/doclinter.py')
-rw-r--r--utils/doclinter.py59
1 files changed, 59 insertions, 0 deletions
diff --git a/utils/doclinter.py b/utils/doclinter.py
new file mode 100644
index 000000000..3f711bfa5
--- /dev/null
+++ b/utils/doclinter.py
@@ -0,0 +1,59 @@
+"""
+ utils.doclinter
+ ~~~~~~~~~~~~~~~
+
+ A linter for Sphinx docs
+
+ :copyright: Copyright 2007-2019 by the Sphinx team, see AUTHORS.
+ :license: BSD, see LICENSE for details.
+"""
+
+import os
+import re
+import sys
+from typing import List
+
+
+MAX_LINE_LENGTH = 100
+
+
+def lint(path: str) -> int:
+ with open(path) as f:
+ document = f.readlines()
+
+ errors = 0
+ for i, line in enumerate(document):
+ if line.endswith(' '):
+ print('%s:%d: the line ends with whitespace.' %
+ (path, i + 1))
+ errors += 1
+
+ if len(line) > MAX_LINE_LENGTH:
+ if re.match(r'^\s*\.\. ', line):
+ # ignore directives and hyperlink targets
+ pass
+ else:
+ print('%s:%d: the line is too long (%d > %d).' %
+ (path, i + 1, len(line), MAX_LINE_LENGTH))
+ errors += 1
+
+ return errors
+
+
+def main(args: List[str]) -> int:
+ errors = 0
+ for directory in args:
+ for root, dirs, files in os.walk(directory):
+ for filename in files:
+ if filename.endswith('.rst'):
+ path = os.path.join(root, filename)
+ errors += lint(path)
+
+ if errors:
+ return 1
+ else:
+ return 0
+
+
+if __name__ == '__main__':
+ sys.exit(main(sys.argv[1:]))