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

Function CheckBracesSpacing

analytical_engine/misc/cpplint.py:4051–4137  ·  view source on GitHub ↗

Checks for horizontal spacing near commas. Args: filename: The name of the current file. clean_lines: A CleansedLines instance containing the file. linenum: The number of the line to check. nesting_state: A NestingState instance which maintains information about

(filename, clean_lines, linenum, nesting_state, error)

Source from the content-addressed store, hash-verified

4049
4050
4051def CheckBracesSpacing(filename, clean_lines, linenum, nesting_state, error):
4052 """Checks for horizontal spacing near commas.
4053
4054 Args:
4055 filename: The name of the current file.
4056 clean_lines: A CleansedLines instance containing the file.
4057 linenum: The number of the line to check.
4058 nesting_state: A NestingState instance which maintains information about
4059 the current stack of nested blocks being parsed.
4060 error: The function to call with any errors found.
4061 """
4062 line = clean_lines.elided[linenum]
4063
4064 # Except after an opening paren, or after another opening brace (in case of
4065 # an initializer list, for instance), you should have spaces before your
4066 # braces when they are delimiting blocks, classes, namespaces etc.
4067 # And since you should never have braces at the beginning of a line,
4068 # this is an easy test. Except that braces used for initialization don't
4069 # follow the same rule; we often don't want spaces before those.
4070 match = Match(r'^(.*[^ ({>]){', line)
4071
4072 if match:
4073 # Try a bit harder to check for brace initialization. This
4074 # happens in one of the following forms:
4075 # Constructor() : initializer_list_{} { ... }
4076 # Constructor{}.MemberFunction()
4077 # Type variable{};
4078 # FunctionCall(type{}, ...);
4079 # LastArgument(..., type{});
4080 # LOG(INFO) << type{} << " ...";
4081 # map_of_type[{...}] = ...;
4082 # ternary = expr ? new type{} : nullptr;
4083 # OuterTemplate<InnerTemplateConstructor<Type>{}>
4084 #
4085 # We check for the character following the closing brace, and
4086 # silence the warning if it's one of those listed above, i.e.
4087 # "{.;,)<>]:".
4088 #
4089 # To account for nested initializer list, we allow any number of
4090 # closing braces up to "{;,)<". We can't simply silence the
4091 # warning on first sight of closing brace, because that would
4092 # cause false negatives for things that are not initializer lists.
4093 # Silence this: But not this:
4094 # Outer{ if (...) {
4095 # Inner{...} if (...){ // Missing space before {
4096 # }; }
4097 #
4098 # There is a false negative with this approach if people inserted
4099 # spurious semicolons, e.g. "if (cond){};", but we will catch the
4100 # spurious semicolon with a separate check.
4101 leading_text = match.group(1)
4102 (endline, endlinenum, endpos) = CloseExpression(
4103 clean_lines, linenum, len(match.group(1)))
4104 trailing_text = ''
4105 if endpos > -1:
4106 trailing_text = endline[endpos:]
4107 for offset in xrange(endlinenum + 1,
4108 min(endlinenum + 3, clean_lines.NumLines() - 1)):

Callers 1

CheckStyleFunction · 0.85

Calls 6

CloseExpressionFunction · 0.85
_IsTypeFunction · 0.85
SearchFunction · 0.85
NumLinesMethod · 0.80
MatchFunction · 0.70
groupMethod · 0.45

Tested by

no test coverage detected