Skip to content

Commit

Permalink
printLocation: Remove trailing whitespace from empty lines
Browse files Browse the repository at this point in the history
  • Loading branch information
leebyron committed Sep 11, 2019
1 parent ff282d7 commit 1239997
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
16 changes: 5 additions & 11 deletions src/language/__tests__/lexer-test.js
Expand Up @@ -111,24 +111,18 @@ describe('Lexer', () => {
it('errors respect whitespace', () => {
let caughtError;
try {
lexOne(dedent`
?
`);
lexOne(['', '', ' ?', ''].join('\n'));
} catch (error) {
caughtError = error;
}
expect(String(caughtError) + '\n').to.equal(dedent`
Syntax Error: Cannot parse the unexpected character "?".
GraphQL request:3:5
2 |
2 |
3 | ?
| ^
4 |
4 |
`);
});

Expand All @@ -145,10 +139,10 @@ describe('Lexer', () => {
Syntax Error: Cannot parse the unexpected character "?".
foo.js:13:6
12 |
12 |
13 | ?
| ^
14 |
14 |
`);
});

Expand Down
2 changes: 1 addition & 1 deletion src/language/__tests__/printLocation-test.js
Expand Up @@ -73,7 +73,7 @@ describe('printSourceLocation', () => {
Test:9:1
9 | *
| ^
10 |
10 |
`);
});
});
4 changes: 3 additions & 1 deletion src/language/printLocation.js
Expand Up @@ -72,7 +72,9 @@ function printPrefixedLines(lines: $ReadOnlyArray<[string, string]>): string {

const padLen = Math.max(...existingLines.map(([prefix]) => prefix.length));
return existingLines
.map(([prefix, line]) => lpad(padLen, prefix) + ' | ' + line)
.map(
([prefix, line]) => lpad(padLen, prefix) + (line ? ' | ' + line : ' |'),
)
.join('\n');
}

Expand Down

0 comments on commit 1239997

Please sign in to comment.