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)
| 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.""" |
no test coverage detected