Skip to content

Commit

Permalink
[printError] Make location formatting IDE friendly (#1949)
Browse files Browse the repository at this point in the history
This is the format used by jest, flow, typescript, and many others.
  • Loading branch information
alloy authored and IvanGoncharov committed Jun 4, 2019
1 parent c3dd670 commit b42f8c8
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 11 deletions.
8 changes: 4 additions & 4 deletions src/error/__tests__/printError-test.js
Expand Up @@ -27,7 +27,7 @@ describe('printError', () => {
expect(printError(singleDigit)).to.equal(dedent`
Single digit line number with no padding
Test (9:1)
Test:9:1
9: *
^
`);
Expand All @@ -41,7 +41,7 @@ describe('printError', () => {
expect(printError(doubleDigit)).to.equal(dedent`
Left padded first line number
Test (9:1)
Test:9:1
9: *
^
10:
Expand Down Expand Up @@ -85,13 +85,13 @@ describe('printError', () => {
expect(printError(error)).to.equal(dedent`
Example error with two nodes
SourceA (2:10)
SourceA:2:10
1: type Foo {
2: field: String
^
3: }
SourceB (2:10)
SourceB:2:10
1: type Foo {
2: field: Int
^
Expand Down
2 changes: 1 addition & 1 deletion src/error/printError.js
Expand Up @@ -59,7 +59,7 @@ function highlightSourceAtLocation(

const lines = body.split(/\r\n|[\n\r]/g);
return (
`${source.name} (${lineNum}:${columnNum})\n` +
`${source.name}:${lineNum}:${columnNum}\n` +
printPrefixedLines([
// Lines specified like this: ["prefix", "string"],
[`${lineNum - 1}: `, lines[lineIndex - 1]],
Expand Down
6 changes: 3 additions & 3 deletions src/language/__tests__/lexer-test.js
Expand Up @@ -127,7 +127,7 @@ describe('Lexer', () => {
expect(String(caughtError)).to.equal(dedent`
Syntax Error: Cannot parse the unexpected character "?".
GraphQL request (3:5)
GraphQL request:3:5
2:
3: ?
^
Expand All @@ -147,7 +147,7 @@ describe('Lexer', () => {
expect(String(caughtError)).to.equal(dedent`
Syntax Error: Cannot parse the unexpected character "?".
foo.js (13:6)
foo.js:13:6
12:
13: ?
^
Expand All @@ -166,7 +166,7 @@ describe('Lexer', () => {
expect(String(caughtError)).to.equal(dedent`
Syntax Error: Cannot parse the unexpected character "?".
foo.js (1:5)
foo.js:1:5
1: ?
^
`);
Expand Down
4 changes: 2 additions & 2 deletions src/language/__tests__/parser-test.js
Expand Up @@ -54,7 +54,7 @@ describe('Parser', () => {
expect(String(caughtError)).to.equal(dedent`
Syntax Error: Expected Name, found <EOF>
GraphQL request (1:2)
GraphQL request:1:2
1: {
^
`);
Expand Down Expand Up @@ -91,7 +91,7 @@ describe('Parser', () => {
expect(String(caughtError)).to.equal(dedent`
Syntax Error: Expected {, found <EOF>
MyQuery.graphql (1:6)
MyQuery.graphql:1:6
1: query
^
`);
Expand Down
2 changes: 1 addition & 1 deletion src/utilities/__tests__/stripIgnoredCharacters-test.js
Expand Up @@ -165,7 +165,7 @@ describe('stripIgnoredCharacters', () => {
expectStripped('{ foo(arg: "\n"').toThrow(dedent`
Syntax Error: Unterminated string.
GraphQL request (1:13)
GraphQL request:1:13
1: { foo(arg: "
^
2: "
Expand Down

0 comments on commit b42f8c8

Please sign in to comment.