MCPcopy Create free account
hub / github.com/alibaba/GraphScope / CheckCommaSpacing

Function CheckCommaSpacing

analytical_engine/misc/cpplint.py:3952–3985  ·  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

3950
3951
3952def CheckCommaSpacing(filename, clean_lines, linenum, error):
3953 """Checks for horizontal spacing near commas and semicolons.
3954
3955 Args:
3956 filename: The name of the current file.
3957 clean_lines: A CleansedLines instance containing the file.
3958 linenum: The number of the line to check.
3959 error: The function to call with any errors found.
3960 """
3961 raw = clean_lines.lines_without_raw_strings
3962 line = clean_lines.elided[linenum]
3963
3964 # You should always have a space after a comma (either as fn arg or operator)
3965 #
3966 # This does not apply when the non-space character following the
3967 # comma is another comma, since the only time when that happens is
3968 # for empty macro arguments.
3969 #
3970 # We run this check in two passes: first pass on elided lines to
3971 # verify that lines contain missing whitespaces, second pass on raw
3972 # lines to confirm that those missing whitespaces are not due to
3973 # elided comments.
3974 if (Search(r',[^,\s]', ReplaceAll(r'\boperator\s*,\s*\(', 'F(', line)) and
3975 Search(r',[^,\s]', raw[linenum])):
3976 error(filename, linenum, 'whitespace/comma', 3,
3977 'Missing space after ,')
3978
3979 # You should always have a space after a semicolon
3980 # except for few corner cases
3981 # TODO(unknown): clarify if 'if (1) { return 1;}' is requires one more
3982 # space after ;
3983 if Search(r';[^\s};\\)/]', line):
3984 error(filename, linenum, 'whitespace/semicolon', 3,
3985 'Missing space after ;')
3986
3987
3988def _IsType(clean_lines, nesting_state, expr):

Callers 1

CheckStyleFunction · 0.85

Calls 2

SearchFunction · 0.85
ReplaceAllFunction · 0.85

Tested by

no test coverage detected