MCPcopy Create free account
hub / github.com/OpenMS/OpenMS / CheckBracesSpacing

Function CheckBracesSpacing

src/tests/coding/cpplint.py:4048–4134  ·  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

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