MCPcopy Index your code
hub / github.com/nodejs/node / CheckSectionSpacing

Function CheckSectionSpacing

tools/cpplint.py:4733–4794  ·  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 obj

(filename, clean_lines, class_info, linenum, error)

Source from the content-addressed store, hash-verified

4731
4732
4733def CheckSectionSpacing(filename, clean_lines, class_info, linenum, error):
4734 """Checks for additional blank line issues related to sections.
4735
4736 Currently the only thing checked here is blank line before protected/private.
4737
4738 Args:
4739 filename: The name of the current file.
4740 clean_lines: A CleansedLines instance containing the file.
4741 class_info: A _ClassInfo objects.
4742 linenum: The number of the line to check.
4743 error: The function to call with any errors found.
4744 """
4745 # Skip checks if the class is small, where small means 25 lines or less.
4746 # 25 lines seems like a good cutoff since that's the usual height of
4747 # terminals, and any class that can't fit in one screen can't really
4748 # be considered "small".
4749 #
4750 # Also skip checks if we are on the first line. This accounts for
4751 # classes that look like
4752 # class Foo { public: ... };
4753 #
4754 # If we didn't find the end of the class, last_line would be zero,
4755 # and the check will be skipped by the first condition.
4756 if (
4757 class_info.last_line - class_info.starting_linenum <= 24
4758 or linenum <= class_info.starting_linenum
4759 ):
4760 return
4761
4762 matched = re.match(r"\s*(public|protected|private):", clean_lines.lines[linenum])
4763 if matched:
4764 # Issue warning if the line before public/protected/private was
4765 # not a blank line, but don't do this if the previous line contains
4766 # "class" or "struct". This can happen two ways:
4767 # - We are at the beginning of the class.
4768 # - We are forward-declaring an inner class that is semantically
4769 # private, but needed to be public for implementation reasons.
4770 # Also ignores cases where the previous line ends with a backslash as can be
4771 # common when defining classes in C macros.
4772 prev_line = clean_lines.lines[linenum - 1]
4773 if (
4774 not IsBlankLine(prev_line)
4775 and not re.search(r"\b(class|struct)\b", prev_line)
4776 and not re.search(r"\\$", prev_line)
4777 ):
4778 # Try a bit harder to find the beginning of the class. This is to
4779 # account for multi-line base-specifier lists, e.g.:
4780 # class Derived
4781 # : public Base {
4782 end_class_head = class_info.starting_linenum
4783 for i in range(class_info.starting_linenum, linenum):
4784 if re.search(r"\{\s*$", clean_lines.lines[i]):
4785 end_class_head = i
4786 break
4787 if end_class_head < linenum - 1:
4788 error(
4789 filename,
4790 linenum,

Callers 1

CheckStyleFunction · 0.85

Calls 5

IsBlankLineFunction · 0.85
matchMethod · 0.65
rangeFunction · 0.50
errorFunction · 0.50
searchMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…