Skip to content

Commit

Permalink
Created renderers for the E1 category
Browse files Browse the repository at this point in the history
  • Loading branch information
Bruce-8 committed Aug 5, 2023
1 parent 97746f7 commit 878aa5c
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 1 deletion.
2 changes: 2 additions & 0 deletions python_ta/config/.pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ class-attribute-rgx = ([A-Za-z_][A-Za-z0-9_]{0,30}|(__.*__))$
# Ignored pycodestyle checks
pycodestyle-ignore =
E111, # pylint W0311
E112, # pylint E0001
E113, # pylint E0001
E114, # pylint W0311
E117, # pylint W0311
E401, # pylint C0410
Expand Down
60 changes: 59 additions & 1 deletion python_ta/reporters/node_printers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from astroid import nodes

NEW_BLANK_LINE_MESSAGE = "# INSERT NEW BLANK LINE HERE"
NEW_INDENT_MESSAGE = "# INSERT NEW INDENT HERE"


def render_message(msg, node, source_lines):
Expand Down Expand Up @@ -132,7 +133,13 @@ def render_missing_space_in_doctest(msg, _node, source_lines=None):

def render_pep8_errors(msg, _node, source_lines=None):
"""Render a PEP8 error message."""
if "expected 1 blank line," in msg.msg:
if "continuation line missing indentation or outdented" in msg.msg:
yield from render_pep8_errors_e122(msg, _node, source_lines)
elif "continuation line over-indented for visual indent" in msg.msg:
yield from render_pep8_errors_e127(msg, _node, source_lines)
elif "continuation line unaligned for hanging indent" in msg.msg:
yield from render_pep8_errors_e131(msg, _node, source_lines)
elif "expected 1 blank line," in msg.msg:
yield from render_pep8_errors_e301(msg, _node, source_lines)
elif "expected 2 blank lines," in msg.msg:
yield from render_pep8_errors_e302(msg, _node, source_lines)
Expand All @@ -153,6 +160,57 @@ def render_blank_line(line):
yield (line + 1, slice(None, None), LineType.ERROR, " " * 28)


def render_pep8_errors_e122(msg, _node, source_lines=None):
"""Render a PEP8 continuation line missing indentation or outdented message."""
line = msg.line - 1
yield from render_context(line - 1, line + 1, source_lines)
yield (
line + 1,
slice(0, len(NEW_INDENT_MESSAGE)),
LineType.ERROR,
NEW_INDENT_MESSAGE + source_lines[line],
)
yield from render_context(msg.line + 1, msg.line + 3, source_lines)


def render_pep8_errors_e127(msg, _node, source_lines=None):
"""Render a PEP8 continuation line over-indented for visual indent message."""
line = msg.line - 1
first_non_space_prev_line_index = 0
first_non_space_msg_line_index = 0
while source_lines[line - 1][first_non_space_prev_line_index] == " ":
first_non_space_prev_line_index += 1
while source_lines[line][first_non_space_msg_line_index] == " ":
first_non_space_msg_line_index += 1
yield from render_context(line - 1, line + 1, source_lines)
yield (
line + 1,
slice(first_non_space_prev_line_index + 4, first_non_space_msg_line_index),
LineType.ERROR,
source_lines[line],
)
yield from render_context(msg.line + 1, msg.line + 3, source_lines)


def render_pep8_errors_e131(msg, _node, source_lines=None):
"""Render a PEP8 continuation line unaligned for hanging indent message."""
line = msg.line - 1
first_non_space_prev_line_index = 0
first_non_space_msg_line_index = 0
while source_lines[line - 1][first_non_space_prev_line_index] == " ":
first_non_space_prev_line_index += 1
while source_lines[line][first_non_space_msg_line_index] == " ":
first_non_space_msg_line_index += 1
yield from render_context(line - 1, line + 1, source_lines)
yield (
line + 1,
slice(first_non_space_prev_line_index, first_non_space_msg_line_index),
LineType.ERROR,
source_lines[line],
)
yield from render_context(msg.line + 1, msg.line + 3, source_lines)


def render_pep8_errors_e301(msg, _node, source_lines=None):
"""Render a PEP8 expected 1 blank line message."""
line = msg.line - 1
Expand Down

0 comments on commit 878aa5c

Please sign in to comment.