33 from roslint
import cpplint
35 from functools
import partial
41 cpplint._line_length = 120
45 """ Decorator to easily allow wrapping/overriding of the Check* functions in cpplint. Should 46 decorate a function which matches the signature of the function it replaces expect with 47 the addition of a fn parameter, which is a pass-through of the replaced function, in case 48 the replacement would like call through to the original functionality. """ 49 def wrap(override_fn):
50 original_fn = getattr(original_module, override_fn.__name__)
51 setattr(original_module, override_fn.__name__, partial(override_fn, original_fn))
58 def makeErrorFn(original_fn, suppress_categories, suppress_message_matches):
59 """ Create a return a wrapped version of the error-report function which suppresses specific 61 def newError(filename, linenum, category, confidence, message):
62 if category
in suppress_categories:
64 if True in [bool(
Match(r, message))
for r
in suppress_message_matches]:
66 original_fn(filename, linenum, category, confidence, message)
72 """ Replacement for the function which determines the header guard variable, to pick one which 73 matches ROS C++ Style. """ 77 head, tail = os.path.split(head)
78 var_parts.insert(0, tail)
79 if head.endswith(
'include')
or os.path.exists(os.path.join(head,
"package.xml"))
or tail ==
"":
81 return re.sub(
r'[-./\s]',
'_',
"_".join(var_parts)).upper()
86 """ Complete replacement for cpplint.CheckBraces, since the brace rules for ROS C++ Style 87 are completely different from the Google style guide ones. """ 88 line = clean_lines.elided[linenum]
89 if Match(
r'^(.*){(.*)}.*$', line):
96 m =
Match(
r'^(.*){(.*)$', line)
99 if "=" in line
and Match(
r'\)( *){$', line):
103 error(filename, linenum,
'whitespace/braces', 4,
104 'when starting a new scope, { should be on a line by itself')
105 m =
Match(
r'^(.*)}(.*)$', line)
107 if m.group(2) !=
";":
108 error(filename, linenum,
'whitespace/braces', 4,
109 '} should be on a line by itself')
115 """ Run the function to get include state, but suppress all the errors, since 116 ROS C++ Style is silent on include order, and contains no prohibition on use of streams. """ 117 fn(filename, clean_lines, linenum, include_state,
118 makeErrorFn(error, [
'build/include_order',
'build/include_alpha',
'readability/streams'], []))
122 def CheckSpacing(fn, filename, clean_lines, linenum, nesting_state, error):
123 """ Do most of the original Spacing checks, but suppress the ones related to braces, since 124 the ROS C++ Style rules are different. """ 125 fn(filename, clean_lines, linenum, nesting_state,
126 makeErrorFn(error, [
'readability/braces',
'whitespace/braces'], []))
130 def ProcessLine(fn, filename, file_extension, clean_lines, line,
131 include_state, function_state, nesting_state, error,
132 extra_check_functions=[]):
133 """ Squelch the error about access control indents. """ 134 fn(filename, file_extension, clean_lines, line,
135 include_state, function_state, nesting_state,
136 makeErrorFn(error, [], [
r'(.*)should be indented \+1 space inside(.*)']),
137 extra_check_functions=[])
142 """ Look for empty loop/conditional body with only a single semicolon, 143 but allow ros-style do while loops. """ 144 from cpplint
import CloseExpression
152 line = clean_lines.elided[linenum]
153 matched =
Match(
r'\s*(for|while|if)\s*\(', line)
157 clean_lines, linenum, line.find(
'('))
163 if end_pos >= 0
and Match(
r';', end_line[end_pos:]):
164 if matched.group(1) ==
'if':
165 error(filename, end_linenum,
166 'whitespace/empty_conditional_body', 5,
167 'Empty conditional bodies should use {}')
168 elif matched.group(1) ==
'while' and linenum
is not 0 \
169 and "}" in clean_lines.elided[linenum-1]:
176 error(filename, end_linenum,
'whitespace/empty_loop_body', 5,
177 'Empty loop bodies should use {} or continue')
def ProcessLine(fn, filename, file_extension, clean_lines, line, include_state, function_state, nesting_state, error, extra_check_functions=[])
def CheckSpacing(fn, filename, clean_lines, linenum, nesting_state, error)
def CheckIncludeLine(fn, filename, clean_lines, linenum, include_state, error)
def CheckEmptyBlockBody(fn, filename, clean_lines, linenum, error)
def CloseExpression(clean_lines, linenum, pos)
def GetHeaderGuardCPPVariable(fn, filename)
def makeErrorFn(original_fn, suppress_categories, suppress_message_matches)
def patch(original_module)
def CheckBraces(fn, filename, clean_lines, linenum, error)