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)
| 838 | self.lines_in_function += 1 |
| 839 | |
| 840 | def Check(self, error, filename, linenum): |
| 841 | """Report if too many lines in function body. |
| 842 | |
| 843 | Args: |
| 844 | error: The function to call with any errors found. |
| 845 | filename: The name of the current file. |
| 846 | linenum: The number of the line to check. |
| 847 | """ |
| 848 | if Match(r'T(EST|est)', self.current_function): |
| 849 | base_trigger = self._TEST_TRIGGER |
| 850 | else: |
| 851 | base_trigger = self._NORMAL_TRIGGER |
| 852 | trigger = base_trigger * 2**_VerboseLevel() |
| 853 | |
| 854 | if self.lines_in_function > trigger: |
| 855 | error_level = int(math.log(self.lines_in_function / base_trigger, 2)) |
| 856 | # 50 => 0, 100 => 1, 200 => 2, 400 => 3, 800 => 4, 1600 => 5, ... |
| 857 | if error_level > 5: |
| 858 | error_level = 5 |
| 859 | error(filename, linenum, 'readability/fn_size', error_level, |
| 860 | 'Small and focused functions are preferred:' |
| 861 | ' %s has %d non-comment lines' |
| 862 | ' (error triggered by exceeding %d lines).' % ( |
| 863 | self.current_function, self.lines_in_function, trigger)) |
| 864 | |
| 865 | def End(self): |
| 866 | """Stop analyzing function body.""" |
no test coverage detected