aboutsummaryrefslogtreecommitdiff
path: root/clint.py
diff options
context:
space:
mode:
authorZyX <kp-pav@yandex.ru>2016-04-13 03:01:03 +0300
committerZyX <kp-pav@yandex.ru>2016-04-13 03:06:35 +0300
commit4a6328a8eb7d2964f0290c4fc32eea31931d6114 (patch)
tree3b0710d4e5ff63a4985f898a19b5713d2023aede /clint.py
parent0cb2c39ec4b5649667619441b2ef3407e0bf9759 (diff)
downloadrneovim-4a6328a8eb7d2964f0290c4fc32eea31931d6114.tar.gz
rneovim-4a6328a8eb7d2964f0290c4fc32eea31931d6114.tar.bz2
rneovim-4a6328a8eb7d2964f0290c4fc32eea31931d6114.zip
clint: Add rule for preincrement/predecrement
Diffstat (limited to 'clint.py')
-rwxr-xr-xclint.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/clint.py b/clint.py
index 60e44cdf36..d7aa866e35 100755
--- a/clint.py
+++ b/clint.py
@@ -191,6 +191,7 @@ _ERROR_CATEGORIES = [
'readability/nul',
'readability/todo',
'readability/utf8',
+ 'readability/increment',
'runtime/arrays',
'runtime/int',
'runtime/invalid_increment',
@@ -3199,6 +3200,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,
@@ -3489,6 +3507,7 @@ def main():
if __name__ == '__main__':
main()
+# vim: ts=4 sts=4 sw=4
# Ignore "too complex" warnings when using pymode.
# pylama:ignore=C901