diff options
author | rebortg <github@ghlr.de> | 2020-12-10 11:59:42 +0100 |
---|---|---|
committer | rebortg <github@ghlr.de> | 2020-12-10 11:59:42 +0100 |
commit | 763324b0c17c9f6724589c2f2c590b4e611a2347 (patch) | |
tree | 04145ee8fc403817628cf594c64e22797de795df | |
parent | 95a2a8af1835a3409430e24352056f44ba07e6c5 (diff) | |
download | vyos-documentation-763324b0c17c9f6724589c2f2c590b4e611a2347.tar.gz vyos-documentation-763324b0c17c9f6724589c2f2c590b4e611a2347.zip |
styleguide: specify line lenght and exception
-rw-r--r-- | .github/vyos-linter.py | 69 | ||||
-rw-r--r-- | docs/contributing/documentation.rst | 10 |
2 files changed, 40 insertions, 39 deletions
diff --git a/.github/vyos-linter.py b/.github/vyos-linter.py index 69a1c8e7..ebf00b2d 100644 --- a/.github/vyos-linter.py +++ b/.github/vyos-linter.py @@ -67,51 +67,40 @@ def lint_linelen(cnt, line): if len(line) > 80: return (f"Line too long: len={len(line)}", cnt, 'warning') - -def handle_file(path, file): - errors = [] - path = '/'.join(path) - filepath = f"{path}/{file}" - try: - with open(filepath) as fp: - line = fp.readline() - cnt = 1 - while line: - err_mac = lint_mac(cnt, line.strip()) - err_ip4 = lint_ipv4(cnt, line.strip()) - err_ip6 = lint_ipv6(cnt, line.strip()) - err_len = lint_linelen(cnt, line.strip()) - if err_mac: - errors.append(err_mac) - if err_ip4: - errors.append(err_ip4) - if err_ip6: - errors.append(err_ip6) - if err_len: - errors.append(err_len) - line = fp.readline() - cnt += 1 - finally: - fp.close() - - if len(errors) > 0: - print(f"File: {filepath}") - for error in errors: - print(error) - print('') - return False - def handle_file_action(filepath): errors = [] try: with open(filepath) as fp: line = fp.readline() cnt = 1 + test_line_lenght = True + indentation = 0 while line: + # ignore every '.. code-block::' for line lenght + # rst code-block have its own style in html the format in rst + # and the build page must be the same + if test_line_lenght is False: + if len(line) > indentation: + #print(f"'{line}'") + #print(indentation) + if line[indentation].isspace() is False: + test_line_lenght = True + + if ".. code-block::" in line: + test_line_lenght = False + indentation = 0 + for i in line: + if i.isspace(): + indentation = indentation + 1 + else: + break err_mac = lint_mac(cnt, line.strip()) err_ip4 = lint_ipv4(cnt, line.strip()) err_ip6 = lint_ipv6(cnt, line.strip()) - err_len = lint_linelen(cnt, line.strip()) + if test_line_lenght: + err_len = lint_linelen(cnt, line) + else: + err_len = None if err_mac: errors.append(err_mac) if err_ip4: @@ -142,17 +131,19 @@ def main(): try: files = ast.literal_eval(sys.argv[1]) for file in files: - print(file) - if file[-4:] == ".rst": + if file[-4:] in [".rst", ".txt"] and "_build" not in file: if handle_file_action(file) is False: bool_error = False except Exception as e: for root, dirs, files in os.walk("docs"): path = root.split(os.sep) for file in files: - if file[-4:] == ".rst": - if handle_file(path, file) is False: + if file[-4:] in [".rst", ".txt"] and "_build" not in path: + fpath = '/'.join(path) + filepath = f"{fpath}/{file}" + if handle_file_action(filepath) is False: bool_error = False + return bool_error diff --git a/docs/contributing/documentation.rst b/docs/contributing/documentation.rst index ddd21396..f1dc8095 100644 --- a/docs/contributing/documentation.rst +++ b/docs/contributing/documentation.rst @@ -153,6 +153,16 @@ system numbers for the documentation: Please don't use other public address space. + +Line length +^^^^^^^^^^^ + +Limit all lines to a maximum of 79 characters. + +Except in ``.. code-block::`` because it will use the html tag ``<pre>`` +which have the save line format as in the rst file. + + Custom Sphinx-doc Markup ^^^^^^^^^^^^^^^^^^^^^^^^ |