MCPcopy Create free account
hub / github.com/alibaba/GraphScope / CheckSectionSpacing

Function CheckSectionSpacing

analytical_engine/misc/cpplint.py:4157–4209  ·  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

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