diff options
Diffstat (limited to 'clint.py')
-rwxr-xr-x | clint.py | 33 |
1 files changed, 32 insertions, 1 deletions
@@ -191,6 +191,7 @@ _ERROR_CATEGORIES = [ 'readability/nul', 'readability/todo', 'readability/utf8', + 'readability/increment', 'runtime/arrays', 'runtime/int', 'runtime/invalid_increment', @@ -2291,6 +2292,11 @@ def CheckSpacing(filename, clean_lines, linenum, nesting_state, error): # there's too little whitespace, we get concerned. It's hard to tell, # though, so we punt on this one for now. TODO. + match = Search(r'(?:[^ (*/![])+(?<!\+\+|--)\*', line) + if match: + error(filename, linenum, 'whitespace/operators', 2, + 'Missing space before asterisk in %s' % match.group(0)) + # You should always have whitespace around binary operators. # # Check <= and >= first to avoid false positives with < and >, then @@ -2299,6 +2305,13 @@ def CheckSpacing(filename, clean_lines, linenum, nesting_state, error): if match: error(filename, linenum, 'whitespace/operators', 3, 'Missing spaces around %s' % match.group(1)) + + # Boolean operators should be placed on the next line. + if Search(r'(?:&&|\|\|)$', line): + error(filename, linenum, 'whitespace/operators', 4, + 'Boolean operator should be placed on the same line as the start ' + 'of its right operand') + # We allow no-spaces around << when used like this: 10<<20, but # not otherwise (particularly, not when used as streams) # Also ignore using ns::operator<<; @@ -2552,7 +2565,7 @@ def CheckBraces(filename, clean_lines, linenum, error): # If should always have a brace for blockstart in ('if', 'while', 'for'): - if Match(r'\s*{0}[^{{]*$'.format(blockstart), line): + if Match(r'\s*{0}(?!\w)[^{{]*$'.format(blockstart), line): pos = line.find(blockstart) pos = line.find('(', pos) if pos > 0: @@ -3194,6 +3207,23 @@ def CheckLanguage(filename, clean_lines, linenum, file_extension, error(filename, linenum, 'readability/bool', 4, 'Use %s instead of %s.' % (token.lower(), token)) + # Detect preincrement/predecrement + match = Match(r'^\s*(?:\+\+|--)', line) + if match: + error(filename, linenum, 'readability/increment', 5, + 'Do not use preincrement in statements, ' + 'use postincrement instead') + # Detect preincrement/predecrement in for(;; preincrement) + match = Search(r';\s*(\+\+|--)', line) + if match: + end_pos, end_depth = FindEndOfExpressionInLine(line, match.start(1), 1, + '(', ')') + expr = line[match.start(1):end_pos] + if end_depth == 0 and ';' not in expr and ' = ' not in expr: + error(filename, linenum, 'readability/increment', 4, + 'Do not use preincrement in statements, including ' + 'for(;; action)') + def ProcessLine(filename, file_extension, clean_lines, line, include_state, function_state, nesting_state, error, @@ -3484,6 +3514,7 @@ def main(): if __name__ == '__main__': main() +# vim: ts=4 sts=4 sw=4 # Ignore "too complex" warnings when using pymode. # pylama:ignore=C901 |