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

Method Check

tools/cpplint.py:1705–1734  ·  view source on GitHub ↗

Report if too many lines in function body. Args: error: The function to call with any errors found. filename: The name of the current file. linenum: The number of the line to check.

(self, error, filename, linenum)

Source from the content-addressed store, hash-verified

1703 self.lines_in_function += 1
1704
1705 def Check(self, error, filename, linenum):
1706 """Report if too many lines in function body.
1707
1708 Args:
1709 error: The function to call with any errors found.
1710 filename: The name of the current file.
1711 linenum: The number of the line to check.
1712 """
1713 if not self.in_a_function:
1714 return
1715
1716 if re.match(r"T(EST|est)", self.current_function):
1717 base_trigger = self._TEST_TRIGGER
1718 else:
1719 base_trigger = self._NORMAL_TRIGGER
1720 trigger = base_trigger * 2 ** _VerboseLevel()
1721
1722 if self.lines_in_function > trigger:
1723 error_level = int(math.log2(self.lines_in_function / base_trigger))
1724 # 50 => 0, 100 => 1, 200 => 2, 400 => 3, 800 => 4, 1600 => 5, ...
1725 error_level = min(error_level, 5)
1726 error(
1727 filename,
1728 linenum,
1729 "readability/fn_size",
1730 error_level,
1731 "Small and focused functions are preferred:"
1732 f" {self.current_function} has {self.lines_in_function} non-comment lines"
1733 f" (error triggered by exceeding {trigger} lines).",
1734 )
1735
1736 def End(self):
1737 """Stop analyzing function body."""

Callers 1

CheckForFunctionLengthsFunction · 0.80

Calls 5

_VerboseLevelFunction · 0.85
intFunction · 0.85
minFunction · 0.85
matchMethod · 0.65
errorFunction · 0.50

Tested by

no test coverage detected