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

Function CheckSectionSpacing

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

2989
2990
2991def CheckSectionSpacing(filename, clean_lines, class_info, linenum, error):
2992 """Checks for additional blank line issues related to sections.
2993
2994 Currently the only thing checked here is blank line before protected/private.
2995
2996 Args:
2997 filename: The name of the current file.
2998 clean_lines: A CleansedLines instance containing the file.
2999 class_info: A _ClassInfo objects.
3000 linenum: The number of the line to check.
3001 error: The function to call with any errors found.
3002 """
3003 # Skip checks if the class is small, where small means 25 lines or less.
3004 # 25 lines seems like a good cutoff since that's the usual height of
3005 # terminals, and any class that can't fit in one screen can't really
3006 # be considered "small".
3007 #
3008 # Also skip checks if we are on the first line. This accounts for
3009 # classes that look like
3010 # class Foo { public: ... };
3011 #
3012 # If we didn't find the end of the class, last_line would be zero,
3013 # and the check will be skipped by the first condition.
3014 if (class_info.last_line - class_info.starting_linenum <= 24 or
3015 linenum <= class_info.starting_linenum):
3016 return
3017
3018 matched = Match(r'\s*(public|protected|private):', clean_lines.lines[linenum])
3019 if matched:
3020 # Issue warning if the line before public/protected/private was
3021 # not a blank line, but don't do this if the previous line contains
3022 # "class" or "struct". This can happen two ways:
3023 # - We are at the beginning of the class.
3024 # - We are forward-declaring an inner class that is semantically
3025 # private, but needed to be public for implementation reasons.
3026 # Also ignores cases where the previous line ends with a backslash as can be
3027 # common when defining classes in C macros.
3028 prev_line = clean_lines.lines[linenum - 1]
3029 if (not IsBlankLine(prev_line) and
3030 not Search(r'\b(class|struct)\b', prev_line) and
3031 not Search(r'\\$', prev_line)):
3032 # Try a bit harder to find the beginning of the class. This is to
3033 # account for multi-line base-specifier lists, e.g.:
3034 # class Derived
3035 # : public Base {
3036 end_class_head = class_info.starting_linenum
3037 for i in range(class_info.starting_linenum, linenum):
3038 if Search(r'\{\s*$', clean_lines.lines[i]):
3039 end_class_head = i
3040 break
3041 if end_class_head < linenum - 1:
3042 error(filename, linenum, 'whitespace/blank_line', 3,
3043 '"%s:" should be preceded by a blank line' % matched.group(1))
3044
3045
3046def GetPreviousNonBlankLine(clean_lines, linenum):

Callers 1

CheckStyleFunction · 0.85

Calls 4

MatchFunction · 0.85
IsBlankLineFunction · 0.85
SearchFunction · 0.85
errorFunction · 0.85

Tested by

no test coverage detected