From b036c84398c1c57bcc0dd5f04a168422355727c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eloy=20Dur=C3=A1n?= Date: Tue, 4 Jun 2019 16:34:51 +0200 Subject: [PATCH] [printError] Make location formatting IDE friendly This is the format used by jest, flow, typescript, and many others. --- src/error/__tests__/printError-test.js | 8 ++++---- src/error/printError.js | 2 +- src/language/__tests__/lexer-test.js | 6 +++--- src/language/__tests__/parser-test.js | 4 ++-- src/utilities/__tests__/stripIgnoredCharacters-test.js | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/error/__tests__/printError-test.js b/src/error/__tests__/printError-test.js index fcd65ff041..a67a45dff2 100644 --- a/src/error/__tests__/printError-test.js +++ b/src/error/__tests__/printError-test.js @@ -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: * ^ `); @@ -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: @@ -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 ^ diff --git a/src/error/printError.js b/src/error/printError.js index f05da20bdd..dca61dd4e5 100644 --- a/src/error/printError.js +++ b/src/error/printError.js @@ -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]], diff --git a/src/language/__tests__/lexer-test.js b/src/language/__tests__/lexer-test.js index e91099b9f9..50da874763 100644 --- a/src/language/__tests__/lexer-test.js +++ b/src/language/__tests__/lexer-test.js @@ -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: ? ^ @@ -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: ? ^ @@ -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: ? ^ `); diff --git a/src/language/__tests__/parser-test.js b/src/language/__tests__/parser-test.js index b5460158d3..9729b7d656 100644 --- a/src/language/__tests__/parser-test.js +++ b/src/language/__tests__/parser-test.js @@ -54,7 +54,7 @@ describe('Parser', () => { expect(String(caughtError)).to.equal(dedent` Syntax Error: Expected Name, found - GraphQL request (1:2) + GraphQL request:1:2 1: { ^ `); @@ -91,7 +91,7 @@ describe('Parser', () => { expect(String(caughtError)).to.equal(dedent` Syntax Error: Expected {, found - MyQuery.graphql (1:6) + MyQuery.graphql:1:6 1: query ^ `); diff --git a/src/utilities/__tests__/stripIgnoredCharacters-test.js b/src/utilities/__tests__/stripIgnoredCharacters-test.js index eb9dc63468..be5787e138 100644 --- a/src/utilities/__tests__/stripIgnoredCharacters-test.js +++ b/src/utilities/__tests__/stripIgnoredCharacters-test.js @@ -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: "