diff options
Diffstat (limited to 'designate/hacking/checks.py')
-rw-r--r-- | designate/hacking/checks.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/designate/hacking/checks.py b/designate/hacking/checks.py index 0a3a6c2d..53de95ce 100644 --- a/designate/hacking/checks.py +++ b/designate/hacking/checks.py @@ -27,6 +27,7 @@ import pycodestyle # D708: Do not use xrange. Use range for large loops. # D709: LOG.audit is deprecated, please use LOG.info! # D710: LOG.warn() is not allowed. Use LOG.warning() +# D711: Don't use backslashes for line continuation. UNDERSCORE_IMPORT_FILES = [] @@ -44,6 +45,7 @@ graduated_oslo_libraries_import_re = re.compile( r"^\s*(?:import|from) designate\.openstack\.common\.?.*?" r"(gettextutils|rpc)" r".*?") +no_line_continuation_backslash_re = re.compile(r'.*(\\)\n') @core.flake8ext @@ -161,3 +163,25 @@ def check_no_log_warn(logical_line): """ if logical_line.startswith('LOG.warn('): yield(0, "D710:Use LOG.warning() rather than LOG.warn()") + + +@core.flake8ext +def check_line_continuation_no_backslash(logical_line, tokens): + """D711 - Don't use backslashes for line continuation. + + :param logical_line: The logical line to check. Not actually used. + :param tokens: List of tokens to check. + :returns: None if the tokens don't contain any issues, otherwise a tuple + is yielded that contains the offending index in the logical + line and a message describe the check validation failure. + """ + backslash = None + for token_type, text, start, end, orig_line in tokens: + m = no_line_continuation_backslash_re.match(orig_line) + if m: + backslash = (start[0], m.start(1)) + break + + if backslash is not None: + msg = 'D711 Backslash line continuations not allowed' + yield backslash, msg |