Skip to content

Commit

Permalink
fix `Parsing error: Cannot read properties of undefined (reading '0')…
Browse files Browse the repository at this point in the history
… eslint` in VSCode (#1725)
  • Loading branch information
dimaMachina authored Jul 2, 2023
1 parent 77ddf45 commit 5f3f1a5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/grumpy-tips-call.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-eslint/eslint-plugin': patch
---

fix `Parsing error: Cannot read properties of undefined (reading '0') eslint` in VSCode
9 changes: 6 additions & 3 deletions packages/plugin/src/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,13 @@ export function parseForESLint(code: string, options: ParserOptions): GraphQLESL
// In case of GraphQL parser error, we report it to ESLint as a parser error that matches the requirements
// of ESLint. This will make sure to display it correctly in IDEs and lint results.
if (error instanceof GraphQLError) {
const location = error.locations?.[0];
const eslintError = {
index: error.positions![0],
lineNumber: error.locations![0].line,
column: error.locations![0].column - 1,
index: error.positions?.[0],
...(location && {
lineNumber: location.line,
column: location.column - 1,
}),
message: error.message,
};
throw eslintError;
Expand Down

0 comments on commit 5f3f1a5

Please sign in to comment.