MCPcopy Index your code
hub / github.com/nodejs/node / CheckCommaSpacing

Function CheckCommaSpacing

tools/cpplint.py:4522–4555  ·  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

4520
4521
4522def CheckCommaSpacing(filename, clean_lines, linenum, error):
4523 """Checks for horizontal spacing near commas and semicolons.
4524
4525 Args:
4526 filename: The name of the current file.
4527 clean_lines: A CleansedLines instance containing the file.
4528 linenum: The number of the line to check.
4529 error: The function to call with any errors found.
4530 """
4531 raw = clean_lines.lines_without_raw_strings
4532 line = clean_lines.elided[linenum]
4533
4534 # You should always have a space after a comma (either as fn arg or operator)
4535 #
4536 # This does not apply when the non-space character following the
4537 # comma is another comma, since the only time when that happens is
4538 # for empty macro arguments.
4539 #
4540 # We run this check in two passes: first pass on elided lines to
4541 # verify that lines contain missing whitespaces, second pass on raw
4542 # lines to confirm that those missing whitespaces are not due to
4543 # elided comments.
4544 match = re.search(
4545 r",[^,\s]", re.sub(r"\b__VA_OPT__\s*\(,\)", "", re.sub(r"\boperator\s*,\s*\(", "F(", line))
4546 )
4547 if match and re.search(r",[^,\s]", raw[linenum]):
4548 error(filename, linenum, "whitespace/comma", 3, "Missing space after ,")
4549
4550 # You should always have a space after a semicolon
4551 # except for few corner cases
4552 # TODO(google): clarify if 'if (1) { return 1;}' is requires one more
4553 # space after ;
4554 if re.search(r";[^\s};\\)/]", line):
4555 error(filename, linenum, "whitespace/semicolon", 3, "Missing space after ;")
4556
4557
4558def _IsType(clean_lines, nesting_state, expr):

Callers 1

CheckStyleFunction · 0.85

Calls 2

errorFunction · 0.50
searchMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…