Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

printLocation: Remove trailing whitespace from empty lines #2162

Merged
merged 1 commit into from Sep 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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