Skip to content

Commit 6adf99c

Browse files
committed
print_location: Remove trailing whitespace from empty lines
Replicates graphql/graphql-js@5c42dc6
1 parent 03c18b7 commit 6adf99c

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

src/graphql/language/print_location.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,5 +70,9 @@ def print_prefixed_lines(*lines: Tuple[str, Optional[str]]) -> str:
7070
]
7171
pad_len = max(len(line[0]) for line in existing_lines)
7272
return "\n".join(
73-
map(lambda line: line[0].rjust(pad_len) + " | " + line[1], existing_lines)
73+
map(
74+
lambda line: line[0].rjust(pad_len)
75+
+ (" | " + line[1] if line[1] else " |"),
76+
existing_lines,
77+
)
7478
)

tests/error/test_print_location.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,6 @@ def prints_line_numbers_with_correct_padding():
7575
Test:9:1
7676
9 | *
7777
| ^
78-
10 |\x20
78+
10 |
7979
"""
8080
)

tests/language/test_lexer.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,17 @@ def skips_whitespace_and_comments():
6161

6262
def errors_respect_whitespace():
6363
with raises(GraphQLSyntaxError) as exc_info:
64-
lex_one("\n\n ?\n\n\n")
64+
lex_one("\n\n ?\n")
6565

6666
assert str(exc_info.value) + "\n" == dedent(
6767
"""
6868
Syntax Error: Cannot parse the unexpected character '?'.
6969
7070
GraphQL request:3:5
71-
2 |\x20
71+
2 |
7272
3 | ?
7373
| ^
74-
4 |\x20
74+
4 |
7575
"""
7676
)
7777

@@ -85,10 +85,10 @@ def updates_line_numbers_in_error_for_file_context():
8585
Syntax Error: Cannot parse the unexpected character '?'.
8686
8787
foo.js:13:6
88-
12 |\x20
88+
12 |
8989
13 | ?
9090
| ^
91-
14 |\x20
91+
14 |
9292
"""
9393
)
9494

0 commit comments

Comments
 (0)