MCPcopy Create free account
hub / github.com/4paradigm/OpenMLDB / CheckStyle

Function CheckStyle

steps/cpplint.py:4820–4943  ·  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

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

Callers 1

ProcessLineFunction · 0.85

Calls 15

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

Tested by

no test coverage detected