mirror of
https://github.com/neovim/neovim.git
synced 2025-11-16 07:11:20 +00:00
clint: Add rule for preincrement/predecrement
This commit is contained in:
19
clint.py
19
clint.py
@@ -191,6 +191,7 @@ _ERROR_CATEGORIES = [
|
|||||||
'readability/nul',
|
'readability/nul',
|
||||||
'readability/todo',
|
'readability/todo',
|
||||||
'readability/utf8',
|
'readability/utf8',
|
||||||
|
'readability/increment',
|
||||||
'runtime/arrays',
|
'runtime/arrays',
|
||||||
'runtime/int',
|
'runtime/int',
|
||||||
'runtime/invalid_increment',
|
'runtime/invalid_increment',
|
||||||
@@ -3199,6 +3200,23 @@ def CheckLanguage(filename, clean_lines, linenum, file_extension,
|
|||||||
error(filename, linenum, 'readability/bool', 4,
|
error(filename, linenum, 'readability/bool', 4,
|
||||||
'Use %s instead of %s.' % (token.lower(), token))
|
'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,
|
def ProcessLine(filename, file_extension, clean_lines, line,
|
||||||
include_state, function_state, nesting_state, error,
|
include_state, function_state, nesting_state, error,
|
||||||
@@ -3489,6 +3507,7 @@ def main():
|
|||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
||||||
|
# vim: ts=4 sts=4 sw=4
|
||||||
|
|
||||||
# Ignore "too complex" warnings when using pymode.
|
# Ignore "too complex" warnings when using pymode.
|
||||||
# pylama:ignore=C901
|
# pylama:ignore=C901
|
||||||
|
|||||||
Reference in New Issue
Block a user