MCPcopy Create free account
hub / github.com/BoomingTech/Piccolo / CheckEmptyBlockBody

Function CheckEmptyBlockBody

engine/3rdparty/tinyobjloader/deps/cpplint.py:4143–4175  ·  view source on GitHub ↗

Look for empty loop/conditional body with only a single semicolon. Args: filename: The name of the current file. clean_lines: A CleansedLines instance containing the file. linenum: The number of the line to check. error: The function to call with any errors found.

(filename, clean_lines, linenum, error)

Source from the content-addressed store, hash-verified

4141
4142
4143def CheckEmptyBlockBody(filename, clean_lines, linenum, error):
4144 """Look for empty loop/conditional body with only a single semicolon.
4145
4146 Args:
4147 filename: The name of the current file.
4148 clean_lines: A CleansedLines instance containing the file.
4149 linenum: The number of the line to check.
4150 error: The function to call with any errors found.
4151 """
4152
4153 # Search for loop keywords at the beginning of the line. Because only
4154 # whitespaces are allowed before the keywords, this will also ignore most
4155 # do-while-loops, since those lines should start with closing brace.
4156 #
4157 # We also check "if" blocks here, since an empty conditional block
4158 # is likely an error.
4159 line = clean_lines.elided[linenum]
4160 matched = Match(r'\s*(for|while|if)\s*\(', line)
4161 if matched:
4162 # Find the end of the conditional expression
4163 (end_line, end_linenum, end_pos) = CloseExpression(
4164 clean_lines, linenum, line.find('('))
4165
4166 # Output warning if what follows the condition expression is a semicolon.
4167 # No warning for all other cases, including whitespace or newline, since we
4168 # have a separate check for semicolons preceded by whitespace.
4169 if end_pos >= 0 and Match(r';', end_line[end_pos:]):
4170 if matched.group(1) == 'if':
4171 error(filename, end_linenum, 'whitespace/empty_conditional_body', 5,
4172 'Empty conditional bodies should use {}')
4173 else:
4174 error(filename, end_linenum, 'whitespace/empty_loop_body', 5,
4175 'Empty loop bodies should use {} or continue')
4176
4177
4178def FindCheckMacro(line):

Callers 1

CheckStyleFunction · 0.85

Calls 4

MatchFunction · 0.85
CloseExpressionFunction · 0.85
errorFunction · 0.50
findMethod · 0.45

Tested by

no test coverage detected