MCPcopy Create free account
hub / github.com/apache/mesos / CheckSectionSpacing

Function CheckSectionSpacing

support/cpplint.py:3658–3710  ·  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

3656
3657
3658def CheckSectionSpacing(filename, clean_lines, class_info, linenum, error):
3659 """Checks for additional blank line issues related to sections.
3660
3661 Currently the only thing checked here is blank line before protected/private.
3662
3663 Args:
3664 filename: The name of the current file.
3665 clean_lines: A CleansedLines instance containing the file.
3666 class_info: A _ClassInfo objects.
3667 linenum: The number of the line to check.
3668 error: The function to call with any errors found.
3669 """
3670 # Skip checks if the class is small, where small means 25 lines or less.
3671 # 25 lines seems like a good cutoff since that's the usual height of
3672 # terminals, and any class that can't fit in one screen can't really
3673 # be considered "small".
3674 #
3675 # Also skip checks if we are on the first line. This accounts for
3676 # classes that look like
3677 # class Foo { public: ... };
3678 #
3679 # If we didn't find the end of the class, last_line would be zero,
3680 # and the check will be skipped by the first condition.
3681 if (class_info.last_line - class_info.starting_linenum <= 24 or
3682 linenum <= class_info.starting_linenum):
3683 return
3684
3685 matched = Match(r'\s*(public|protected|private):', clean_lines.lines[linenum])
3686 if matched:
3687 # Issue warning if the line before public/protected/private was
3688 # not a blank line, but don't do this if the previous line contains
3689 # "class" or "struct". This can happen two ways:
3690 # - We are at the beginning of the class.
3691 # - We are forward-declaring an inner class that is semantically
3692 # private, but needed to be public for implementation reasons.
3693 # Also ignores cases where the previous line ends with a backslash as can be
3694 # common when defining classes in C macros.
3695 prev_line = clean_lines.lines[linenum - 1]
3696 if (not IsBlankLine(prev_line) and
3697 not Search(r'\b(class|struct)\b', prev_line) and
3698 not Search(r'\\$', prev_line)):
3699 # Try a bit harder to find the beginning of the class. This is to
3700 # account for multi-line base-specifier lists, e.g.:
3701 # class Derived
3702 # : public Base {
3703 end_class_head = class_info.starting_linenum
3704 for i in range(class_info.starting_linenum, linenum):
3705 if Search(r'\{\s*$', clean_lines.lines[i]):
3706 end_class_head = i
3707 break
3708 if end_class_head < linenum - 1:
3709 error(filename, linenum, 'whitespace/blank_line', 3,
3710 '"%s:" should be preceded by a blank line' % matched.group(1))
3711
3712
3713def 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