MCPcopy Index your code
hub / github.com/nodejs/node / CheckForFunctionLengths

Function CheckForFunctionLengths

tools/cpplint.py:4068–4135  ·  view source on GitHub ↗

Reports for long function bodies. For an overview why this is done, see: https://google.github.io/styleguide/cppguide.html#Write_Short_Functions Uses a simplistic algorithm assuming other style guidelines (especially spacing) are followed. Only checks unindented functions, so c

(filename, clean_lines, linenum, function_state, error)

Source from the content-addressed store, hash-verified

4066
4067
4068def CheckForFunctionLengths(filename, clean_lines, linenum, function_state, error):
4069 """Reports for long function bodies.
4070
4071 For an overview why this is done, see:
4072 https://google.github.io/styleguide/cppguide.html#Write_Short_Functions
4073
4074 Uses a simplistic algorithm assuming other style guidelines
4075 (especially spacing) are followed.
4076 Only checks unindented functions, so class members are unchecked.
4077 Trivial bodies are unchecked, so constructors with huge initializer lists
4078 may be missed.
4079 Blank/comment lines are not counted so as to avoid encouraging the removal
4080 of vertical space and comments just to get through a lint check.
4081 NOLINT *on the last line of a function* disables this check.
4082
4083 Args:
4084 filename: The name of the current file.
4085 clean_lines: A CleansedLines instance containing the file.
4086 linenum: The number of the line to check.
4087 function_state: Current function name and lines in body so far.
4088 error: The function to call with any errors found.
4089 """
4090 lines = clean_lines.lines
4091 line = lines[linenum]
4092 joined_line = ""
4093
4094 starting_func = False
4095 regexp = r"(\w(\w|::|\*|\&|\s)*)\(" # decls * & space::name( ...
4096 if match_result := re.match(regexp, line):
4097 # If the name is all caps and underscores, figure it's a macro and
4098 # ignore it, unless it's TEST or TEST_F.
4099 function_name = match_result.group(1).split()[-1]
4100 if function_name in {"TEST", "TEST_F"} or not re.match(r"[A-Z_]+$", function_name):
4101 starting_func = True
4102
4103 if starting_func:
4104 body_found = False
4105 for start_linenum in range(linenum, clean_lines.NumLines()):
4106 start_line = lines[start_linenum]
4107 joined_line += " " + start_line.lstrip()
4108 if re.search(r"(;|})", start_line): # Declarations and trivial functions
4109 body_found = True
4110 break # ... ignore
4111 if re.search(r"{", start_line):
4112 body_found = True
4113 function = re.search(r"((\w|:)*)\(", line).group(1)
4114 if re.match(r"TEST", function): # Handle TEST... macros
4115 parameter_regexp = re.search(r"(\(.*\))", joined_line)
4116 if parameter_regexp: # Ignore bad syntax
4117 function += parameter_regexp.group(1)
4118 else:
4119 function += "()"
4120 function_state.Begin(function)
4121 break
4122 if not body_found:
4123 # No body for the function (or evidence of a non-function) was found.
4124 error(
4125 filename,

Callers 1

ProcessLineFunction · 0.85

Calls 10

NumLinesMethod · 0.80
BeginMethod · 0.80
CheckMethod · 0.80
EndMethod · 0.80
CountMethod · 0.80
matchMethod · 0.65
rangeFunction · 0.50
errorFunction · 0.50
splitMethod · 0.45
searchMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…