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)
| 3381 | |
| 3382 | |
| 3383 | def CheckCommaSpacing(filename, clean_lines, linenum, error): |
| 3384 | """Checks for horizontal spacing near commas and semicolons. |
| 3385 | |
| 3386 | Args: |
| 3387 | filename: The name of the current file. |
| 3388 | clean_lines: A CleansedLines instance containing the file. |
| 3389 | linenum: The number of the line to check. |
| 3390 | error: The function to call with any errors found. |
| 3391 | """ |
| 3392 | raw = clean_lines.lines_without_raw_strings |
| 3393 | line = clean_lines.elided[linenum] |
| 3394 | |
| 3395 | # You should always have a space after a comma (either as fn arg or operator) |
| 3396 | # |
| 3397 | # This does not apply when the non-space character following the |
| 3398 | # comma is another comma, since the only time when that happens is |
| 3399 | # for empty macro arguments. |
| 3400 | # |
| 3401 | # We run this check in two passes: first pass on elided lines to |
| 3402 | # verify that lines contain missing whitespaces, second pass on raw |
| 3403 | # lines to confirm that those missing whitespaces are not due to |
| 3404 | # elided comments. |
| 3405 | if (Search(r',[^,\s]', ReplaceAll(r'\boperator\s*,\s*\(', 'F(', line)) and |
| 3406 | Search(r',[^,\s]', raw[linenum])): |
| 3407 | error(filename, linenum, 'whitespace/comma', 3, |
| 3408 | 'Missing space after ,') |
| 3409 | |
| 3410 | # You should always have a space after a semicolon |
| 3411 | # except for few corner cases |
| 3412 | # TODO(unknown): clarify if 'if (1) { return 1;}' is requires one more |
| 3413 | # space after ; |
| 3414 | if Search(r';[^\s};\\)/]', line): |
| 3415 | error(filename, linenum, 'whitespace/semicolon', 3, |
| 3416 | 'Missing space after ;') |
| 3417 | |
| 3418 | |
| 3419 | def _IsType(clean_lines, nesting_state, expr): |
no test coverage detected