MCPcopy Create free account
hub / github.com/OpenMS/OpenMS / CheckSectionSpacing

Function CheckSectionSpacing

src/tests/coding/cpplint.py:4154–4206  ·  view source on GitHub ↗

Checks for additional blank line issues related to sections. Currently the only thing checked here is blank line before protected/private. Args: filename: The name of the current file. clean_lines: A CleansedLines instance containing the file. class_info: A _ClassInfo objects.

(filename, clean_lines, class_info, linenum, error)

Source from the content-addressed store, hash-verified

4152 return False
4153
4154def CheckSectionSpacing(filename, clean_lines, class_info, linenum, error):
4155 """Checks for additional blank line issues related to sections.
4156
4157 Currently the only thing checked here is blank line before protected/private.
4158
4159 Args:
4160 filename: The name of the current file.
4161 clean_lines: A CleansedLines instance containing the file.
4162 class_info: A _ClassInfo objects.
4163 linenum: The number of the line to check.
4164 error: The function to call with any errors found.
4165 """
4166 # Skip checks if the class is small, where small means 25 lines or less.
4167 # 25 lines seems like a good cutoff since that's the usual height of
4168 # terminals, and any class that can't fit in one screen can't really
4169 # be considered "small".
4170 #
4171 # Also skip checks if we are on the first line. This accounts for
4172 # classes that look like
4173 # class Foo { public: ... };
4174 #
4175 # If we didn't find the end of the class, last_line would be zero,
4176 # and the check will be skipped by the first condition.
4177 if (class_info.last_line - class_info.starting_linenum <= 24 or
4178 linenum <= class_info.starting_linenum):
4179 return
4180
4181 matched = Match(r'\s*(public|protected|private):', clean_lines.lines[linenum])
4182 if matched:
4183 # Issue warning if the line before public/protected/private was
4184 # not a blank line, but don't do this if the previous line contains
4185 # "class" or "struct". This can happen two ways:
4186 # - We are at the beginning of the class.
4187 # - We are forward-declaring an inner class that is semantically
4188 # private, but needed to be public for implementation reasons.
4189 # Also ignores cases where the previous line ends with a backslash as can be
4190 # common when defining classes in C macros.
4191 prev_line = clean_lines.lines[linenum - 1]
4192 if (not IsBlankLine(prev_line) and
4193 not Search(r'\b(class|struct)\b', prev_line) and
4194 not Search(r'\\$', prev_line)):
4195 # Try a bit harder to find the beginning of the class. This is to
4196 # account for multi-line base-specifier lists, e.g.:
4197 # class Derived
4198 # : public Base {
4199 end_class_head = class_info.starting_linenum
4200 for i in range(class_info.starting_linenum, linenum):
4201 if Search(r'\{\s*$', clean_lines.lines[i]):
4202 end_class_head = i
4203 break
4204 if end_class_head < linenum - 1:
4205 error(filename, linenum, 'whitespace/blank_line', 3,
4206 '"%s:" should be preceded by a blank line' % matched.group(1))
4207
4208
4209def GetPreviousNonBlankLine(clean_lines, linenum):

Callers 1

CheckStyleFunction · 0.85

Calls 4

IsBlankLineFunction · 0.85
SearchFunction · 0.85
MatchFunction · 0.70
groupMethod · 0.45

Tested by

no test coverage detected