MCPcopy Create free account
hub / github.com/tensorflow/tfjs / CheckForFunctionLengths

Function CheckForFunctionLengths

tfjs-backend-wasm/tools/cpplint.py:3046–3111  ·  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

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

Callers 1

ProcessLineFunction · 0.85

Calls 8

MatchFunction · 0.85
SearchFunction · 0.85
NumLinesMethod · 0.80
BeginMethod · 0.80
CheckMethod · 0.80
EndMethod · 0.80
CountMethod · 0.80
splitMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…