From 113bdc4b2600d3994c78e267e9a2d6aa8347c064 Mon Sep 17 00:00:00 2001 From: Christian Berendt Date: Wed, 7 Jan 2015 11:22:15 +0100 Subject: [PATCH] Adds niceness check to avoid unwanted unicode charaters MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This check helps to avoid the usage of unicode characters like “...” or ‘...’. Change-Id: I53e999fc91336871e1c32c70745f7d7cf2e256cf --- RELEASE_NOTES.rst | 6 ++++++ os_doc_tools/doctest.py | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/RELEASE_NOTES.rst b/RELEASE_NOTES.rst index f69395fd..94ed921b 100644 --- a/RELEASE_NOTES.rst +++ b/RELEASE_NOTES.rst @@ -1,6 +1,12 @@ Release notes ============= +0.22 +---- + +* ``openstack-doc-test``: New niceness check to avoid specific unicode + characters. + 0.21.1 ------ diff --git a/os_doc_tools/doctest.py b/os_doc_tools/doctest.py index e6dda5d4..d48af4d8 100755 --- a/os_doc_tools/doctest.py +++ b/os_doc_tools/doctest.py @@ -1,4 +1,5 @@ #!/usr/bin/env python +# -*- coding: utf8 -*- # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain @@ -208,6 +209,23 @@ def verify_newline_end_of_file(docfile): raise ValueError('last line of a file must end with a \\n') +def verify_unicode_niceness(docfile): + """Check that no unwanted unicode charaters are used.""" + + invalid_characters = '“”‘’―—' + + affected_lines = [] + lc = 0 + for line in open(docfile, 'r'): + lc += 1 + any(c in line for c in invalid_characters) + + if len(affected_lines): + raise ValueError("unwanted unicode charaters (one of %s) " + "found in line(s): %" % (" ".join(invalid_characters), + ", ".join(affected_lines))) + + def verify_whitespace_niceness(docfile): """Check that no unnecessary whitespaces are used.""" checks = [ @@ -530,6 +548,7 @@ def validate_one_json_file(rootdir, path, verbose, check_syntax, if check_niceness: verify_whitespace_niceness(path) verify_newline_end_of_file(path) + verify_unicode_niceness(path) except ValueError as e: any_failures = True print(" %s: %s" % (os.path.relpath(path, rootdir), e)) @@ -561,6 +580,7 @@ def validate_one_file(schema, rootdir, path, verbose, if check_niceness: verify_whitespace_niceness(path) verify_newline_end_of_file(path) + verify_unicode_niceness(path) except etree.XMLSyntaxError as e: any_failures = True print(" %s: %s" % (os.path.relpath(path, rootdir), e))