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

Function CheckParenthesisSpacing

analytical_engine/misc/cpplint.py:3914–3949  ·  view source on GitHub ↗

Checks for horizontal spacing around parentheses. 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

3912
3913
3914def CheckParenthesisSpacing(filename, clean_lines, linenum, error):
3915 """Checks for horizontal spacing around parentheses.
3916
3917 Args:
3918 filename: The name of the current file.
3919 clean_lines: A CleansedLines instance containing the file.
3920 linenum: The number of the line to check.
3921 error: The function to call with any errors found.
3922 """
3923 line = clean_lines.elided[linenum]
3924
3925 # No spaces after an if, while, switch, or for
3926 match = Search(r' (if\(|for\(|while\(|switch\()', line)
3927 if match:
3928 error(filename, linenum, 'whitespace/parens', 5,
3929 'Missing space before ( in %s' % match.group(1))
3930
3931 # For if/for/while/switch, the left and right parens should be
3932 # consistent about how many spaces are inside the parens, and
3933 # there should either be zero or one spaces inside the parens.
3934 # We don't want: "if ( foo)" or "if ( foo )".
3935 # Exception: "for ( ; foo; bar)" and "for (foo; bar; )" are allowed.
3936 match = Search(r'\b(if|for|while|switch)\s*'
3937 r'\(([ ]*)(.).*[^ ]+([ ]*)\)\s*{\s*$',
3938 line)
3939 if match:
3940 if len(match.group(2)) != len(match.group(4)):
3941 if not (match.group(3) == ';' and
3942 len(match.group(2)) == 1 + len(match.group(4)) or
3943 not match.group(2) and Search(r'\bfor\s*\(.*; \)', line)):
3944 error(filename, linenum, 'whitespace/parens', 5,
3945 'Mismatching spaces inside () in %s' % match.group(1))
3946 if len(match.group(2)) not in [0, 1]:
3947 error(filename, linenum, 'whitespace/parens', 5,
3948 'Should have zero or one spaces inside ( and ) in %s' %
3949 match.group(1))
3950
3951
3952def CheckCommaSpacing(filename, clean_lines, linenum, error):

Callers 1

CheckStyleFunction · 0.85

Calls 2

SearchFunction · 0.85
groupMethod · 0.45

Tested by

no test coverage detected