def check_lines_per_function(self, **kwargs):
"""
Inspect the code for too many lines
per function/method.
"""
try:
max_lines = kwargs['max_lines_per_function']
except KeyError:
return
function_definition = self.parsed_code.body[0]
if not isinstance(function_definition, ast.FunctionDef):
return
code_lines = self.code.splitlines()[1:]
# Filter out the lines, which do
# not consist only of whitespaces:
logic_lines = len(list(filter(lambda line:
line != re.search('\s+', line).group(),
code_lines)))
if logic_lines > max_lines:
line_number = function_definition.lineno
self.issues[line_number].add(
self.code_errors.too_many_lines(
logic_lines, max_lines)
)
评论列表
文章目录