diff options
author | ZyX <kp-pav@yandex.ru> | 2015-12-08 13:22:31 +0300 |
---|---|---|
committer | ZyX <kp-pav@yandex.ru> | 2015-12-08 13:22:31 +0300 |
commit | 77836ff01b4cf69089ccefb19a7ab6c8b770934d (patch) | |
tree | 97c6cf54e62d266a4c667851bd0fc30f2168a8a9 /clint.py | |
parent | 6d583f85875499fbe05b549a1c0ac57b9ededd3d (diff) | |
download | rneovim-77836ff01b4cf69089ccefb19a7ab6c8b770934d.tar.gz rneovim-77836ff01b4cf69089ccefb19a7ab6c8b770934d.tar.bz2 rneovim-77836ff01b4cf69089ccefb19a7ab6c8b770934d.zip |
clint: Make sure that braces are always used for if and other clauses
Diffstat (limited to 'clint.py')
-rwxr-xr-x | clint.py | 16 |
1 files changed, 16 insertions, 0 deletions
@@ -2361,11 +2361,27 @@ def CheckBraces(filename, clean_lines, linenum, error): ' of the previous line') # An else clause should be on the same line as the preceding closing brace. + # If there is no preceding closing brace, there should be one. if Match(r'\s*else\s*', line): prevline = GetPreviousNonBlankLine(clean_lines, linenum)[0] if Match(r'\s*}\s*$', prevline): error(filename, linenum, 'whitespace/newline', 4, 'An else should appear on the same line as the preceding }') + else: + error(filename, linenum, 'readability/braces', 5, + 'An else should always have braces before it') + + # If should always have a brace + for blockstart in ('if', 'while', 'for'): + if Match(r'\s*{0}[^{{]*$'.format(blockstart), line): + pos = line.find(blockstart) + pos = line.find('(', pos) + if pos > 0: + (endline, _, endpos) = CloseExpression( + clean_lines, linenum, pos) + if endline[endpos:].find('{') == -1: + error(filename, linenum, 'readability/braces', 5, + '{0} should always use braces'.format(blockstart)) # If braces come on one side of an else, they should be on both. # However, we have to worry about "else if" that spans multiple lines! |