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

Function CheckForFunctionLengths

analytical_engine/misc/cpplint.py:3545–3610  ·  view source on GitHub ↗

Reports for long function bodies. For an overview why this is done, see: https://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Write_Short_Functions Uses a simplistic algorithm assuming other style guidelines (especially spacing) are followed. Only checks unindented functions,

(filename, clean_lines, linenum,
                            function_state, error)

Source from the content-addressed store, hash-verified

3543
3544
3545def CheckForFunctionLengths(filename, clean_lines, linenum,
3546 function_state, error):
3547 """Reports for long function bodies.
3548
3549 For an overview why this is done, see:
3550 https://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Write_Short_Functions
3551
3552 Uses a simplistic algorithm assuming other style guidelines
3553 (especially spacing) are followed.
3554 Only checks unindented functions, so class members are unchecked.
3555 Trivial bodies are unchecked, so constructors with huge initializer lists
3556 may be missed.
3557 Blank/comment lines are not counted so as to avoid encouraging the removal
3558 of vertical space and comments just to get through a lint check.
3559 NOLINT *on the last line of a function* disables this check.
3560
3561 Args:
3562 filename: The name of the current file.
3563 clean_lines: A CleansedLines instance containing the file.
3564 linenum: The number of the line to check.
3565 function_state: Current function name and lines in body so far.
3566 error: The function to call with any errors found.
3567 """
3568 lines = clean_lines.lines
3569 line = lines[linenum]
3570 joined_line = ''
3571
3572 starting_func = False
3573 regexp = r'(\w(\w|::|\*|\&|\s)*)\(' # decls * & space::name( ...
3574 match_result = Match(regexp, line)
3575 if match_result:
3576 # If the name is all caps and underscores, figure it's a macro and
3577 # ignore it, unless it's TEST or TEST_F.
3578 function_name = match_result.group(1).split()[-1]
3579 if function_name == 'TEST' or function_name == 'TEST_F' or (
3580 not Match(r'[A-Z_]+$', function_name)):
3581 starting_func = True
3582
3583 if starting_func:
3584 body_found = False
3585 for start_linenum in xrange(linenum, clean_lines.NumLines()):
3586 start_line = lines[start_linenum]
3587 joined_line += ' ' + start_line.lstrip()
3588 if Search(r'(;|})', start_line): # Declarations and trivial functions
3589 body_found = True
3590 break # ... ignore
3591 if Search(r'{', start_line):
3592 body_found = True
3593 function = Search(r'((\w|:)*)\(', line).group(1)
3594 if Match(r'TEST', function): # Handle TEST... macros
3595 parameter_regexp = Search(r'(\(.*\))', joined_line)
3596 if parameter_regexp: # Ignore bad syntax
3597 function += parameter_regexp.group(1)
3598 else:
3599 function += '()'
3600 function_state.Begin(function)
3601 break
3602 if not body_found:

Callers 1

ProcessLineFunction · 0.85

Calls 9

SearchFunction · 0.85
splitMethod · 0.80
NumLinesMethod · 0.80
BeginMethod · 0.80
CheckMethod · 0.80
EndMethod · 0.80
CountMethod · 0.80
MatchFunction · 0.70
groupMethod · 0.45

Tested by

no test coverage detected