MCPcopy Create free account
hub / github.com/OpenPTrack/open_ptrack_v2 / CheckEmptyBlockBody

Function CheckEmptyBlockBody

rtpose_wrapper/scripts/cpp_lint.py:3243–3275  ·  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

3241
3242
3243def CheckEmptyBlockBody(filename, clean_lines, linenum, error):
3244 """Look for empty loop/conditional body with only a single semicolon.
3245
3246 Args:
3247 filename: The name of the current file.
3248 clean_lines: A CleansedLines instance containing the file.
3249 linenum: The number of the line to check.
3250 error: The function to call with any errors found.
3251 """
3252
3253 # Search for loop keywords at the beginning of the line. Because only
3254 # whitespaces are allowed before the keywords, this will also ignore most
3255 # do-while-loops, since those lines should start with closing brace.
3256 #
3257 # We also check "if" blocks here, since an empty conditional block
3258 # is likely an error.
3259 line = clean_lines.elided[linenum]
3260 matched = Match(r'\s*(for|while|if)\s*\(', line)
3261 if matched:
3262 # Find the end of the conditional expression
3263 (end_line, end_linenum, end_pos) = CloseExpression(
3264 clean_lines, linenum, line.find('('))
3265
3266 # Output warning if what follows the condition expression is a semicolon.
3267 # No warning for all other cases, including whitespace or newline, since we
3268 # have a separate check for semicolons preceded by whitespace.
3269 if end_pos >= 0 and Match(r';', end_line[end_pos:]):
3270 if matched.group(1) == 'if':
3271 error(filename, end_linenum, 'whitespace/empty_conditional_body', 5,
3272 'Empty conditional bodies should use {}')
3273 else:
3274 error(filename, end_linenum, 'whitespace/empty_loop_body', 5,
3275 'Empty loop bodies should use {} or continue')
3276
3277
3278def CheckCheck(filename, clean_lines, linenum, error):

Callers 1

CheckStyleFunction · 0.85

Calls 3

MatchFunction · 0.85
CloseExpressionFunction · 0.85
errorFunction · 0.85

Tested by

no test coverage detected