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)
| 4452 | |
| 4453 | |
| 4454 | def CheckCommaSpacing(filename, clean_lines, linenum, error): |
| 4455 | """Checks for horizontal spacing near commas and semicolons. |
| 4456 | |
| 4457 | Args: |
| 4458 | filename: The name of the current file. |
| 4459 | clean_lines: A CleansedLines instance containing the file. |
| 4460 | linenum: The number of the line to check. |
| 4461 | error: The function to call with any errors found. |
| 4462 | """ |
| 4463 | raw = clean_lines.lines_without_raw_strings |
| 4464 | line = clean_lines.elided[linenum] |
| 4465 | |
| 4466 | # You should always have a space after a comma (either as fn arg or operator) |
| 4467 | # |
| 4468 | # This does not apply when the non-space character following the |
| 4469 | # comma is another comma, since the only time when that happens is |
| 4470 | # for empty macro arguments. |
| 4471 | # |
| 4472 | # We run this check in two passes: first pass on elided lines to |
| 4473 | # verify that lines contain missing whitespaces, second pass on raw |
| 4474 | # lines to confirm that those missing whitespaces are not due to |
| 4475 | # elided comments. |
| 4476 | match = re.search( |
| 4477 | r",[^,\s]", re.sub(r"\b__VA_OPT__\s*\(,\)", "", re.sub(r"\boperator\s*,\s*\(", "F(", line)) |
| 4478 | ) |
| 4479 | if match and re.search(r",[^,\s]", raw[linenum]): |
| 4480 | error(filename, linenum, "whitespace/comma", 3, "Missing space after ,") |
| 4481 | |
| 4482 | # You should always have a space after a semicolon |
| 4483 | # except for few corner cases |
| 4484 | # TODO(google): clarify if 'if (1) { return 1;}' is requires one more |
| 4485 | # space after ; |
| 4486 | if re.search(r";[^\s};\\)/]", line): |
| 4487 | error(filename, linenum, "whitespace/semicolon", 3, "Missing space after ;") |
| 4488 | |
| 4489 | |
| 4490 | def _IsType(clean_lines, nesting_state, expr): |