Skip to content

Commit b908f6c

Browse files
committed
Fix: Considering single skipped line in message, moved to separate method
1 parent 0252538 commit b908f6c

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

adafruit_templateengine.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,12 @@ def __init__(self, message: str, token: Token):
7575
super().__init__(f"{message}\n\n" + self._underline_token_in_template(token))
7676

7777
@staticmethod
78+
def _skipped_lines_message(nr_of_lines: int) -> str:
79+
return f"[{nr_of_lines} line{'s' if nr_of_lines > 1 else ''} skipped]"
80+
81+
@classmethod
7882
def _underline_token_in_template(
79-
token: Token, *, lines_around: int = 4, symbol: str = "^"
83+
cls, token: Token, *, lines_around: int = 4, symbol: str = "^"
8084
) -> str:
8185
"""
8286
Return ``number_of_lines`` lines before and after the token, with the token content underlined
@@ -96,15 +100,16 @@ def _underline_token_in_template(
96100

97101
template_before_token = token.template[: token.start_position]
98102
if (skipped_lines := template_before_token.count("\n") - lines_around) > 0:
99-
template_before_token = f"[{skipped_lines} lines skipped]\n" + "\n".join(
100-
template_before_token.split("\n")[-(lines_around + 1) :]
103+
template_before_token = (
104+
f"{cls._skipped_lines_message(skipped_lines)}\n"
105+
+ "\n".join(template_before_token.split("\n")[-(lines_around + 1) :])
101106
)
102107

103108
template_after_token = token.template[token.end_position :]
104109
if (skipped_lines := template_after_token.count("\n") - lines_around) > 0:
105110
template_after_token = (
106111
"\n".join(template_after_token.split("\n")[: (lines_around + 1)])
107-
+ f"\n[{skipped_lines} lines skipped]"
112+
+ f"\n{cls._skipped_lines_message(skipped_lines)}"
108113
)
109114

110115
lines_before_line_with_token = template_before_token.rsplit("\n", 1)[0]

0 commit comments

Comments
 (0)