aboutsummaryrefslogtreecommitdiff
path: root/clint.py
diff options
context:
space:
mode:
authorZyX <kp-pav@yandex.ru>2015-12-08 13:22:31 +0300
committerZyX <kp-pav@yandex.ru>2015-12-08 13:22:31 +0300
commit77836ff01b4cf69089ccefb19a7ab6c8b770934d (patch)
tree97c6cf54e62d266a4c667851bd0fc30f2168a8a9 /clint.py
parent6d583f85875499fbe05b549a1c0ac57b9ededd3d (diff)
downloadrneovim-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-xclint.py16
1 files changed, 16 insertions, 0 deletions
diff --git a/clint.py b/clint.py
index 0eaab6e3f6..b7b4eef803 100755
--- a/clint.py
+++ b/clint.py
@@ -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!