def check_indentation(self, **kwargs):
"""Inspect the code for indentation size errors."""
try:
indentation_size = kwargs['indentation_size']
except KeyError:
# Use the default value instead:
indentation_size = self.DEFAULT_RULES['indentation_size']
# Traverse the nodes and find those that are nested
# (have 'body' attribute).
nodes = [node for node in ast.walk(self.parsed_code.body[0])
if hasattr(node, 'body')]
# Use the previous line offset
# as a guide for the next line indentation.
last_offset = 0
for node in nodes:
line_number = node.body[0].lineno
col_offset = node.body[0].col_offset
if col_offset > last_offset + indentation_size:
offset = col_offset - last_offset
self.issues[line_number].add(
self.code_errors.indentation(offset, indentation_size)
)
last_offset = col_offset
评论列表
文章目录