Skip to content

Commit 5f3f1a5

Browse files
authored
fix Parsing error: Cannot read properties of undefined (reading '0') eslint in VSCode (#1725)
1 parent 77ddf45 commit 5f3f1a5

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

.changeset/grumpy-tips-call.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphql-eslint/eslint-plugin': patch
3+
---
4+
5+
fix `Parsing error: Cannot read properties of undefined (reading '0') eslint` in VSCode

packages/plugin/src/parser.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,13 @@ export function parseForESLint(code: string, options: ParserOptions): GraphQLESL
6666
// In case of GraphQL parser error, we report it to ESLint as a parser error that matches the requirements
6767
// of ESLint. This will make sure to display it correctly in IDEs and lint results.
6868
if (error instanceof GraphQLError) {
69+
const location = error.locations?.[0];
6970
const eslintError = {
70-
index: error.positions![0],
71-
lineNumber: error.locations![0].line,
72-
column: error.locations![0].column - 1,
71+
index: error.positions?.[0],
72+
...(location && {
73+
lineNumber: location.line,
74+
column: location.column - 1,
75+
}),
7376
message: error.message,
7477
};
7578
throw eslintError;

0 commit comments

Comments
 (0)