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

Function CheckStyle

tools/cpplint.py:5560–5705  ·  view source on GitHub ↗

Checks rules from the 'C++ style rules' section of cppguide.html. Most of these rules are hard to test (naming, comment style), but we do what we can. In particular we check for 2-space indents, line lengths, tab usage, spaces inside code, etc. Args: filename: The name of th

(filename, clean_lines, linenum, file_extension, nesting_state, error, cppvar=None)

Source from the content-addressed store, hash-verified

5558
5559
5560def CheckStyle(filename, clean_lines, linenum, file_extension, nesting_state, error, cppvar=None):
5561 """Checks rules from the 'C++ style rules' section of cppguide.html.
5562
5563 Most of these rules are hard to test (naming, comment style), but we
5564 do what we can. In particular we check for 2-space indents, line lengths,
5565 tab usage, spaces inside code, etc.
5566
5567 Args:
5568 filename: The name of the current file.
5569 clean_lines: A CleansedLines instance containing the file.
5570 linenum: The number of the line to check.
5571 file_extension: The extension (without the dot) of the filename.
5572 nesting_state: A NestingState instance which maintains information about
5573 the current stack of nested blocks being parsed.
5574 error: The function to call with any errors found.
5575 cppvar: The header guard variable returned by GetHeaderGuardCPPVar.
5576 """
5577
5578 # Don't use "elided" lines here, otherwise we can't check commented lines.
5579 # Don't want to use "raw" either, because we don't want to check inside C++11
5580 # raw strings,
5581 raw_lines = clean_lines.lines_without_raw_strings
5582 line = raw_lines[linenum]
5583 prev = raw_lines[linenum - 1] if linenum > 0 else ""
5584
5585 if line.find("\t") != -1:
5586 error(filename, linenum, "whitespace/tab", 1, "Tab found; better to use spaces")
5587
5588 # One or three blank spaces at the beginning of the line is weird; it's
5589 # hard to reconcile that with 2-space indents.
5590 # NOTE: here are the conditions rob pike used for his tests. Mine aren't
5591 # as sophisticated, but it may be worth becoming so: RLENGTH==initial_spaces
5592 # if(RLENGTH > 20) complain = 0;
5593 # if(match($0, " +(error|private|public|protected):")) complain = 0;
5594 # if(match(prev, "&& *$")) complain = 0;
5595 # if(match(prev, "\\|\\| *$")) complain = 0;
5596 # if(match(prev, "[\",=><] *$")) complain = 0;
5597 # if(match($0, " <<")) complain = 0;
5598 # if(match(prev, " +for \\(")) complain = 0;
5599 # if(prevodd && match(prevprev, " +for \\(")) complain = 0;
5600 scope_or_label_pattern = r"\s*(?:public|private|protected|signals)(?:\s+(?:slots\s*)?)?:\s*\\?$"
5601 classinfo = nesting_state.InnermostClass()
5602 initial_spaces = 0
5603 cleansed_line = clean_lines.elided[linenum]
5604 while initial_spaces < len(line) and line[initial_spaces] == " ":
5605 initial_spaces += 1
5606 # There are certain situations we allow one space, notably for
5607 # section labels, and also lines containing multi-line raw strings.
5608 # We also don't check for lines that look like continuation lines
5609 # (of lines ending in double quotes, commas, equals, or angle brackets)
5610 # because the rules for how to indent those are non-trivial.
5611 if (
5612 not re.search(r'[",=><] *$', prev)
5613 and (initial_spaces in {1, 3})
5614 and not re.match(scope_or_label_pattern, cleansed_line)
5615 and not (clean_lines.raw_lines[linenum] != line and re.match(r'^\s*""', line))
5616 ):
5617 error(

Callers 1

ProcessLineFunction · 0.85

Calls 15

IsHeaderExtensionFunction · 0.85
GetLineWidthFunction · 0.85
GetPreviousNonBlankLineFunction · 0.85
CheckBracesFunction · 0.85
CheckTrailingSemicolonFunction · 0.85
CheckEmptyBlockBodyFunction · 0.85
CheckSpacingFunction · 0.85
CheckOperatorSpacingFunction · 0.85
CheckParenthesisSpacingFunction · 0.85
CheckCommaSpacingFunction · 0.85
CheckBracesSpacingFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…