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

Function CheckStyle

analytical_engine/misc/cpplint.py:4810–4933  ·  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 the current

(filename, clean_lines, linenum, file_extension, nesting_state,
               error)

Source from the content-addressed store, hash-verified

4808
4809
4810def CheckStyle(filename, clean_lines, linenum, file_extension, nesting_state,
4811 error):
4812 """Checks rules from the 'C++ style rules' section of cppguide.html.
4813
4814 Most of these rules are hard to test (naming, comment style), but we
4815 do what we can. In particular we check for 2-space indents, line lengths,
4816 tab usage, spaces inside code, etc.
4817
4818 Args:
4819 filename: The name of the current file.
4820 clean_lines: A CleansedLines instance containing the file.
4821 linenum: The number of the line to check.
4822 file_extension: The extension (without the dot) of the filename.
4823 nesting_state: A NestingState instance which maintains information about
4824 the current stack of nested blocks being parsed.
4825 error: The function to call with any errors found.
4826 """
4827
4828 # Don't use "elided" lines here, otherwise we can't check commented lines.
4829 # Don't want to use "raw" either, because we don't want to check inside C++11
4830 # raw strings,
4831 raw_lines = clean_lines.lines_without_raw_strings
4832 line = raw_lines[linenum]
4833 prev = raw_lines[linenum - 1] if linenum > 0 else ''
4834
4835 if line.find('\t') != -1:
4836 error(filename, linenum, 'whitespace/tab', 1,
4837 'Tab found; better to use spaces')
4838
4839 # One or three blank spaces at the beginning of the line is weird; it's
4840 # hard to reconcile that with 2-space indents.
4841 # NOTE: here are the conditions rob pike used for his tests. Mine aren't
4842 # as sophisticated, but it may be worth becoming so: RLENGTH==initial_spaces
4843 # if(RLENGTH > 20) complain = 0;
4844 # if(match($0, " +(error|private|public|protected):")) complain = 0;
4845 # if(match(prev, "&& *$")) complain = 0;
4846 # if(match(prev, "\\|\\| *$")) complain = 0;
4847 # if(match(prev, "[\",=><] *$")) complain = 0;
4848 # if(match($0, " <<")) complain = 0;
4849 # if(match(prev, " +for \\(")) complain = 0;
4850 # if(prevodd && match(prevprev, " +for \\(")) complain = 0;
4851 scope_or_label_pattern = r'\s*(?:public|private|protected|signals)(?:\s+(?:slots\s*)?)?:\s*\\?$'
4852 classinfo = nesting_state.InnermostClass()
4853 initial_spaces = 0
4854 cleansed_line = clean_lines.elided[linenum]
4855 while initial_spaces < len(line) and line[initial_spaces] == ' ':
4856 initial_spaces += 1
4857 # There are certain situations we allow one space, notably for
4858 # section labels, and also lines containing multi-line raw strings.
4859 # We also don't check for lines that look like continuation lines
4860 # (of lines ending in double quotes, commas, equals, or angle brackets)
4861 # because the rules for how to indent those are non-trivial.
4862 if (not Search(r'[",=><] *$', prev) and
4863 (initial_spaces == 1 or initial_spaces == 3) and
4864 not Match(scope_or_label_pattern, cleansed_line) and
4865 not (clean_lines.raw_lines[linenum] != line and
4866 Match(r'^\s*""', line))):
4867 error(filename, linenum, 'whitespace/indent', 3,

Callers 1

ProcessLineFunction · 0.85

Calls 15

SearchFunction · 0.85
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

Tested by

no test coverage detected