MCPcopy Create free account
hub / github.com/apache/mesos / CheckForFunctionLengths

Function CheckForFunctionLengths

support/cpplint.py:3049–3114  ·  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

3047
3048
3049def CheckForFunctionLengths(filename, clean_lines, linenum,
3050 function_state, error):
3051 """Reports for long function bodies.
3052
3053 For an overview why this is done, see:
3054 https://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Write_Short_Functions
3055
3056 Uses a simplistic algorithm assuming other style guidelines
3057 (especially spacing) are followed.
3058 Only checks unindented functions, so class members are unchecked.
3059 Trivial bodies are unchecked, so constructors with huge initializer lists
3060 may be missed.
3061 Blank/comment lines are not counted so as to avoid encouraging the removal
3062 of vertical space and comments just to get through a lint check.
3063 NOLINT *on the last line of a function* disables this check.
3064
3065 Args:
3066 filename: The name of the current file.
3067 clean_lines: A CleansedLines instance containing the file.
3068 linenum: The number of the line to check.
3069 function_state: Current function name and lines in body so far.
3070 error: The function to call with any errors found.
3071 """
3072 lines = clean_lines.lines
3073 line = lines[linenum]
3074 joined_line = ''
3075
3076 starting_func = False
3077 regexp = r'(\w(\w|::|\*|\&|\s)*)\(' # decls * & space::name( ...
3078 match_result = Match(regexp, line)
3079 if match_result:
3080 # If the name is all caps and underscores, figure it's a macro and
3081 # ignore it, unless it's TEST or TEST_F.
3082 function_name = match_result.group(1).split()[-1]
3083 if function_name == 'TEST' or function_name == 'TEST_F' or (
3084 not Match(r'[A-Z_]+$', function_name)):
3085 starting_func = True
3086
3087 if starting_func:
3088 body_found = False
3089 for start_linenum in xrange(linenum, clean_lines.NumLines()):
3090 start_line = lines[start_linenum]
3091 joined_line += ' ' + start_line.lstrip()
3092 if Search(r'(;|})', start_line): # Declarations and trivial functions
3093 body_found = True
3094 break # ... ignore
3095 elif Search(r'{', start_line):
3096 body_found = True
3097 function = Search(r'((\w|:)*)\(', line).group(1)
3098 if Match(r'TEST', function): # Handle TEST... macros
3099 parameter_regexp = Search(r'(\(.*\))', joined_line)
3100 if parameter_regexp: # Ignore bad syntax
3101 function += parameter_regexp.group(1)
3102 else:
3103 function += '()'
3104 function_state.Begin(function)
3105 break
3106 if not body_found:

Callers 1

ProcessLineFunction · 0.85

Calls 8

MatchFunction · 0.85
SearchFunction · 0.85
errorFunction · 0.85
NumLinesMethod · 0.80
BeginMethod · 0.80
CheckMethod · 0.80
EndMethod · 0.80
CountMethod · 0.80

Tested by

no test coverage detected