MCPcopy Create free account
hub / github.com/OpenMS/OpenMS / _FunctionState

Class _FunctionState

src/tests/coding/cpplint.py:1486–1542  ·  view source on GitHub ↗

Tracks current function name and the number of lines in its body.

Source from the content-addressed store, hash-verified

1484 _cpplint_state.RestoreFilters()
1485
1486class _FunctionState(object):
1487 """Tracks current function name and the number of lines in its body."""
1488
1489 _NORMAL_TRIGGER = 250 # for --v=0, 500 for --v=1, etc.
1490 _TEST_TRIGGER = 400 # about 50% more than _NORMAL_TRIGGER.
1491
1492 def __init__(self):
1493 self.in_a_function = False
1494 self.lines_in_function = 0
1495 self.current_function = ''
1496
1497 def Begin(self, function_name):
1498 """Start analyzing function body.
1499
1500 Args:
1501 function_name: The name of the function being tracked.
1502 """
1503 self.in_a_function = True
1504 self.lines_in_function = 0
1505 self.current_function = function_name
1506
1507 def Count(self):
1508 """Count line in current function body."""
1509 if self.in_a_function:
1510 self.lines_in_function += 1
1511
1512 def Check(self, error, filename, linenum):
1513 """Report if too many lines in function body.
1514
1515 Args:
1516 error: The function to call with any errors found.
1517 filename: The name of the current file.
1518 linenum: The number of the line to check.
1519 """
1520 if not self.in_a_function:
1521 return
1522
1523 if Match(r'T(EST|est)', self.current_function):
1524 base_trigger = self._TEST_TRIGGER
1525 else:
1526 base_trigger = self._NORMAL_TRIGGER
1527 trigger = base_trigger * 2**_VerboseLevel()
1528
1529 if self.lines_in_function > trigger:
1530 error_level = int(math.log(self.lines_in_function / base_trigger, 2))
1531 # 50 => 0, 100 => 1, 200 => 2, 400 => 3, 800 => 4, 1600 => 5, ...
1532 if error_level > 5:
1533 error_level = 5
1534 error(filename, linenum, 'readability/fn_size', error_level,
1535 'Small and focused functions are preferred:'
1536 ' %s has %d non-comment lines'
1537 ' (error triggered by exceeding %d lines).' % (
1538 self.current_function, self.lines_in_function, trigger))
1539
1540 def End(self):
1541 """Stop analyzing function body."""
1542 self.in_a_function = False
1543

Callers 1

ProcessFileDataFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected