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

Function CheckCommaSpacing

support/cpplint.py:3452–3485  ·  view source on GitHub ↗

Checks for horizontal spacing near commas and semicolons. Args: filename: The name of the current file. clean_lines: A CleansedLines instance containing the file. linenum: The number of the line to check. error: The function to call with any errors found.

(filename, clean_lines, linenum, error)

Source from the content-addressed store, hash-verified

3450
3451
3452def CheckCommaSpacing(filename, clean_lines, linenum, error):
3453 """Checks for horizontal spacing near commas and semicolons.
3454
3455 Args:
3456 filename: The name of the current file.
3457 clean_lines: A CleansedLines instance containing the file.
3458 linenum: The number of the line to check.
3459 error: The function to call with any errors found.
3460 """
3461 raw = clean_lines.lines_without_raw_strings
3462 line = clean_lines.elided[linenum]
3463
3464 # You should always have a space after a comma (either as fn arg or operator)
3465 #
3466 # This does not apply when the non-space character following the
3467 # comma is another comma, since the only time when that happens is
3468 # for empty macro arguments.
3469 #
3470 # We run this check in two passes: first pass on elided lines to
3471 # verify that lines contain missing whitespaces, second pass on raw
3472 # lines to confirm that those missing whitespaces are not due to
3473 # elided comments.
3474 if (Search(r',[^,\s]', ReplaceAll(r'\boperator\s*,\s*\(', 'F(', line)) and
3475 Search(r',[^,\s]', raw[linenum])):
3476 error(filename, linenum, 'whitespace/comma', 3,
3477 'Missing space after ,')
3478
3479 # You should always have a space after a semicolon
3480 # except for few corner cases
3481 # TODO(unknown): clarify if 'if (1) { return 1;}' is requires one more
3482 # space after ;
3483 if Search(r';[^\s};\\)/]', line):
3484 error(filename, linenum, 'whitespace/semicolon', 3,
3485 'Missing space after ;')
3486
3487
3488def _IsType(clean_lines, nesting_state, expr):

Callers 1

CheckStyleFunction · 0.85

Calls 3

SearchFunction · 0.85
ReplaceAllFunction · 0.85
errorFunction · 0.85

Tested by

no test coverage detected