def CheckBraces(fn, filename, clean_lines, linenum, error): """ Complete replacement for cpplint.CheckBraces, since the brace rules for ROS C++ Style are completely different from the Google style guide ones. """ line = clean_lines.elided[linenum] if Match(r'^(.*){(.*)}.?$', line): # Special case when both braces are on the same line together, as is the # case for one-line getters and setters, for example, or rows of a multi- # dimenstional array initializer. pass else: # Line does not contain both an opening and closing brace. m = Match(r'^(.*){(.*)$', line) if m and not (IsBlankLine(m.group(1))): # Line contains a starting brace and is not empty, uh oh. if "=" in line and Match(r'\)( *){$', line): # Opening brace is permissable in case of an initializer. pass else: error( filename, linenum, 'whitespace/braces', 4, 'when starting a new scope, { should be on a line by itself' ) m = Match(r'^(.*)}(.*)$', line) if m and (not IsBlankLine(m.group(1)) or not IsBlankLine(m.group(2))): if m.group(2) != ";": error(filename, linenum, 'whitespace/braces', 4, '} should be on a line by itself') pass
def newError(filename, linenum, category, confidence, message): if category in suppress_categories: return #if "should be" in message: # print suppress_message_matches, message, [Match(r, message) for r in suppress_message_matches] if True in [bool(Match(r, message)) for r in suppress_message_matches]: return original_fn(filename, linenum, category, confidence, message)
def CheckBraces(fn, filename, clean_lines, linenum, error): """ Complete replacement for cpplint.CheckBraces, since the brace rules for ROS C++ Style are completely different from the Google style guide ones. """ line = clean_lines.elided[linenum] if Match(r'^(.*){(.*)}.?$', line): # Special case when both braces are on the same line together, as is the # case for one-line getters and setters, for example, or rows of a multi- # dimenstional array initializer. pass else: # Line does not contain both an opening and closing brace. m = Match(r'^(.*){(.*)$', line) if m and not (IsBlankLine(m.group(1))): # Line contains a starting brace and is not empty, uh oh. if "=" in line: # Opening brace is permissable in case of an initializer. pass else: error(filename, linenum, 'whitespace/braces', 4, 'when starting a new scope, { should be on a line by itself') m = Match(r'^(.*)}(.*)$', line) if m and (not IsBlankLine(m.group(1)) or not IsBlankLine(m.group(2))): if m.group(2) != ";": error(filename, linenum, 'whitespace/braces', 4, '} should be on a line by itself') pass
def CheckEmptyBlockBody(fn, filename, clean_lines, linenum, error): """ Look for empty loop/conditional body with only a single semicolon, but allow ros-style do while loops. """ from cpplint import CloseExpression # Search for loop keywords at the beginning of the line. Because only # whitespaces are allowed before the keywords, this will also ignore most # do-while-loops, since those lines should start with closing brace. # # We also check "if" blocks here, since an empty conditional block # is likely an error. line = clean_lines.elided[linenum] matched = Match(r'\s*(for|while|if)\s*\(', line) if matched: # Find the end of the conditional expression (end_line, end_linenum, end_pos) = CloseExpression(clean_lines, linenum, line.find('(')) # Output warning if what follows the condition expression is a # semicolon. No warning for all other cases, including # whitespace or newline, since we have a separate check for # semicolons preceded by whitespace. if end_pos >= 0 and Match(r';', end_line[end_pos:]): if matched.group(1) == 'if': error(filename, end_linenum, 'whitespace/empty_conditional_body', 5, 'Empty conditional bodies should use {}') elif matched.group(1) == 'while' and linenum is not 0 \ and "}" in clean_lines.elided[linenum-1]: # Don't report an error for ros style do-whiles. Works # by checking for a closing brace on the previous # line, since that means it's probably a do-while # loop. return else: error(filename, end_linenum, 'whitespace/empty_loop_body', 5, 'Empty loop bodies should use {} or continue')
def CheckEmptyBlockBody(fn, filename, clean_lines, linenum, error): """ Look for empty loop/conditional body with only a single semicolon, but allow ros-style do while loops. """ from cpplint import CloseExpression # Search for loop keywords at the beginning of the line. Because only # whitespaces are allowed before the keywords, this will also ignore most # do-while-loops, since those lines should start with closing brace. # # We also check "if" blocks here, since an empty conditional block # is likely an error. line = clean_lines.elided[linenum] matched = Match(r'\s*(for|while|if)\s*\(', line) if matched: # Find the end of the conditional expression (end_line, end_linenum, end_pos) = CloseExpression( clean_lines, linenum, line.find('(')) # Output warning if what follows the condition expression is a # semicolon. No warning for all other cases, including # whitespace or newline, since we have a separate check for # semicolons preceded by whitespace. if end_pos >= 0 and Match(r';', end_line[end_pos:]): if matched.group(1) == 'if': error(filename, end_linenum, 'whitespace/empty_conditional_body', 5, 'Empty conditional bodies should use {}') elif matched.group(1) == 'while' and linenum is not 0 \ and "}" in clean_lines.elided[linenum-1]: # Don't report an error for ros style do-whiles. Works # by checking for a closing brace on the previous # line, since that means it's probably a do-while # loop. return else: error(filename, end_linenum, 'whitespace/empty_loop_body', 5, 'Empty loop bodies should use {} or continue')
def newError(filename, linenum, category, confidence, message): if category in suppress_categories: return if True in [bool(Match(r, message)) for r in suppress_message_matches]: return original_fn(filename, linenum, category, confidence, message)