Skip to content

Commit 5c42dc6

Browse files
authored
printLocation: Remove trailing whitespace from empty lines (#2162)
1 parent ff282d7 commit 5c42dc6

File tree

3 files changed

+9
-13
lines changed

3 files changed

+9
-13
lines changed

src/language/__tests__/lexer-test.js

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -111,24 +111,18 @@ describe('Lexer', () => {
111111
it('errors respect whitespace', () => {
112112
let caughtError;
113113
try {
114-
lexOne(dedent`
115-
116-
117-
?
118-
119-
120-
`);
114+
lexOne(['', '', ' ?', ''].join('\n'));
121115
} catch (error) {
122116
caughtError = error;
123117
}
124118
expect(String(caughtError) + '\n').to.equal(dedent`
125119
Syntax Error: Cannot parse the unexpected character "?".
126120
127121
GraphQL request:3:5
128-
2 |
122+
2 |
129123
3 | ?
130124
| ^
131-
4 |
125+
4 |
132126
`);
133127
});
134128

@@ -145,10 +139,10 @@ describe('Lexer', () => {
145139
Syntax Error: Cannot parse the unexpected character "?".
146140
147141
foo.js:13:6
148-
12 |
142+
12 |
149143
13 | ?
150144
| ^
151-
14 |
145+
14 |
152146
`);
153147
});
154148

src/language/__tests__/printLocation-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ describe('printSourceLocation', () => {
7373
Test:9:1
7474
9 | *
7575
| ^
76-
10 |
76+
10 |
7777
`);
7878
});
7979
});

src/language/printLocation.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ function printPrefixedLines(lines: $ReadOnlyArray<[string, string]>): string {
7272

7373
const padLen = Math.max(...existingLines.map(([prefix]) => prefix.length));
7474
return existingLines
75-
.map(([prefix, line]) => lpad(padLen, prefix) + ' | ' + line)
75+
.map(
76+
([prefix, line]) => lpad(padLen, prefix) + (line ? ' | ' + line : ' |'),
77+
)
7678
.join('\n');
7779
}
7880

0 commit comments

Comments
 (0)