Skip to content

Commit e171bbc

Browse files
committed
printLocation: Use vertical bar as number column delimiter
1 parent b904859 commit e171bbc

File tree

6 files changed

+35
-39
lines changed

6 files changed

+35
-39
lines changed

src/error/__tests__/GraphQLError-test.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -217,16 +217,16 @@ describe('printError', () => {
217217
Example error with two nodes
218218
219219
SourceA:2:10
220-
1: type Foo {
221-
2: field: String
222-
^
223-
3: }
220+
1 | type Foo {
221+
2 | field: String
222+
| ^
223+
3 | }
224224
225225
SourceB:2:10
226-
1: type Foo {
227-
2: field: Int
228-
^
229-
3: }
226+
1 | type Foo {
227+
2 | field: Int
228+
| ^
229+
3 | }
230230
`);
231231
});
232232
});

src/language/__tests__/lexer-test.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,10 @@ describe('Lexer', () => {
122122
Syntax Error: Cannot parse the unexpected character "?".
123123
124124
GraphQL request:3:5
125-
2:
126-
3: ?
127-
^
128-
4:
125+
2 |
126+
3 | ?
127+
| ^
128+
4 |
129129
`);
130130
});
131131

@@ -142,10 +142,10 @@ describe('Lexer', () => {
142142
Syntax Error: Cannot parse the unexpected character "?".
143143
144144
foo.js:13:6
145-
12:
146-
13: ?
147-
^
148-
14:
145+
12 |
146+
13 | ?
147+
| ^
148+
14 |
149149
`);
150150
});
151151

@@ -161,8 +161,8 @@ describe('Lexer', () => {
161161
Syntax Error: Cannot parse the unexpected character "?".
162162
163163
foo.js:1:5
164-
1: ?
165-
^
164+
1 | ?
165+
| ^
166166
`);
167167
});
168168

src/language/__tests__/parser-test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ describe('Parser', () => {
4848
Syntax Error: Expected Name, found <EOF>
4949
5050
GraphQL request:1:2
51-
1: {
52-
^
51+
1 | {
52+
| ^
5353
`);
5454

5555
expectSyntaxError(
@@ -85,8 +85,8 @@ describe('Parser', () => {
8585
Syntax Error: Expected {, found <EOF>
8686
8787
MyQuery.graphql:1:6
88-
1: query
89-
^
88+
1 | query
89+
| ^
9090
`);
9191
});
9292

src/language/__tests__/printLocation-test.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ describe('printLocation', () => {
1616

1717
expect(result + '\n').to.equal(dedent`
1818
Test:9:1
19-
9: *
20-
^
19+
9 | *
20+
| ^
2121
`);
2222
});
2323

@@ -29,9 +29,9 @@ describe('printLocation', () => {
2929

3030
expect(result + '\n').to.equal(dedent`
3131
Test:9:1
32-
9: *
33-
^
34-
10:
32+
9 | *
33+
| ^
34+
10 |
3535
`);
3636
});
3737
});

src/language/printLocation.js

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,24 +36,20 @@ export function printSourceLocation(
3636
`${source.name}:${lineNum}:${columnNum}\n` +
3737
printPrefixedLines([
3838
// Lines specified like this: ["prefix", "string"],
39-
[`${lineNum - 1}: `, lines[lineIndex - 1]],
40-
[`${lineNum}: `, lines[lineIndex]],
39+
[`${lineNum - 1}`, lines[lineIndex - 1]],
40+
[`${lineNum}`, lines[lineIndex]],
4141
['', whitespace(columnNum - 1) + '^'],
42-
[`${lineNum + 1}: `, lines[lineIndex + 1]],
42+
[`${lineNum + 1}`, lines[lineIndex + 1]],
4343
])
4444
);
4545
}
4646

4747
function printPrefixedLines(lines: Array<[string, string]>): string {
4848
const existingLines = lines.filter(([_, line]) => line !== undefined);
4949

50-
let padLen = 0;
51-
for (const [prefix] of existingLines) {
52-
padLen = Math.max(padLen, prefix.length);
53-
}
54-
50+
const padLen = Math.max(...existingLines.map(([prefix]) => prefix.length));
5551
return existingLines
56-
.map(([prefix, line]) => lpad(padLen, prefix) + line)
52+
.map(([prefix, line]) => lpad(padLen, prefix) + ' | ' + line)
5753
.join('\n');
5854
}
5955

src/utilities/__tests__/stripIgnoredCharacters-test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,9 @@ describe('stripIgnoredCharacters', () => {
157157
Syntax Error: Unterminated string.
158158
159159
GraphQL request:1:13
160-
1: { foo(arg: "
161-
^
162-
2: "
160+
1 | { foo(arg: "
161+
| ^
162+
2 | "
163163
`);
164164
});
165165

0 commit comments

Comments
 (0)