MCPcopy Create free account
hub / github.com/apache/mesos / CheckBracesSpacing

Function CheckBracesSpacing

support/cpplint.py:3551–3637  ·  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

3549
3550
3551def CheckBracesSpacing(filename, clean_lines, linenum, nesting_state, error):
3552 """Checks for horizontal spacing near commas.
3553
3554 Args:
3555 filename: The name of the current file.
3556 clean_lines: A CleansedLines instance containing the file.
3557 linenum: The number of the line to check.
3558 nesting_state: A NestingState instance which maintains information about
3559 the current stack of nested blocks being parsed.
3560 error: The function to call with any errors found.
3561 """
3562 line = clean_lines.elided[linenum]
3563
3564 # Except after an opening paren, or after another opening brace (in case of
3565 # an initializer list, for instance), you should have spaces before your
3566 # braces when they are delimiting blocks, classes, namespaces etc.
3567 # And since you should never have braces at the beginning of a line,
3568 # this is an easy test. Except that braces used for initialization don't
3569 # follow the same rule; we often don't want spaces before those.
3570 match = Match(r'^(.*[^ ({>]){', line)
3571
3572 if match:
3573 # Try a bit harder to check for brace initialization. This
3574 # happens in one of the following forms:
3575 # Constructor() : initializer_list_{} { ... }
3576 # Constructor{}.MemberFunction()
3577 # Type variable{};
3578 # FunctionCall(type{}, ...);
3579 # LastArgument(..., type{});
3580 # LOG(INFO) << type{} << " ...";
3581 # map_of_type[{...}] = ...;
3582 # ternary = expr ? new type{} : nullptr;
3583 # OuterTemplate<InnerTemplateConstructor<Type>{}>
3584 #
3585 # We check for the character following the closing brace, and
3586 # silence the warning if it's one of those listed above, i.e.
3587 # "{.;,)<>]:".
3588 #
3589 # To account for nested initializer list, we allow any number of
3590 # closing braces up to "{;,)<". We can't simply silence the
3591 # warning on first sight of closing brace, because that would
3592 # cause false negatives for things that are not initializer lists.
3593 # Silence this: But not this:
3594 # Outer{ if (...) {
3595 # Inner{...} if (...){ // Missing space before {
3596 # }; }
3597 #
3598 # There is a false negative with this approach if people inserted
3599 # spurious semicolons, e.g. "if (cond){};", but we will catch the
3600 # spurious semicolon with a separate check.
3601 leading_text = match.group(1)
3602 (endline, endlinenum, endpos) = CloseExpression(
3603 clean_lines, linenum, len(match.group(1)))
3604 trailing_text = ''
3605 if endpos > -1:
3606 trailing_text = endline[endpos:]
3607 for offset in xrange(endlinenum + 1,
3608 min(endlinenum + 3, clean_lines.NumLines() - 1)):

Callers 1

CheckStyleFunction · 0.85

Calls 7

MatchFunction · 0.85
CloseExpressionFunction · 0.85
minFunction · 0.85
_IsTypeFunction · 0.85
errorFunction · 0.85
SearchFunction · 0.85
NumLinesMethod · 0.80

Tested by

no test coverage detected