Skip to content

Commit a5e1e6e

Browse files
committed
Fix issues with processor parsing errors breaking the eslint execution
1 parent aeb4ae1 commit a5e1e6e

File tree

2 files changed

+30
-20
lines changed

2 files changed

+30
-20
lines changed

.changeset/little-steaks-punch.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@graphql-eslint/eslint-plugin': patch
3+
---
4+
5+
Fix issues with processor parsing errors breaking the eslint execution

packages/plugin/src/processors/code-files.ts

+25-20
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,36 @@ export function createGraphqlProcessor() {
2323
// WORKAROUND: This restores the original filename for the block representing original code.
2424
// This allows to be compatible with other eslint plugins relying on filesystem
2525
// This is temporary, waiting for https://github.com/eslint/eslint/issues/11989
26-
const originalFileBlock = { text, filename: `/../../${basename(filename)}` }
26+
const originalFileBlock = { text, filename: `/../../${basename(filename)}` };
2727

2828
if (filename && text && RELEVANT_KEYWORDS.some(keyword => text.includes(keyword))) {
29-
const extractedDocuments = parseCode({
30-
code: text,
31-
filePath: filename,
32-
options: {
33-
globalGqlIdentifierName: ['gql', 'graphql'],
34-
skipIndent: true,
35-
},
36-
});
29+
try {
30+
const extractedDocuments = parseCode({
31+
code: text,
32+
filePath: filename,
33+
options: {
34+
globalGqlIdentifierName: ['gql', 'graphql'],
35+
skipIndent: true,
36+
},
37+
});
3738

38-
if (extractedDocuments && extractedDocuments.length > 0) {
39-
for (const item of extractedDocuments) {
40-
blocks.push({
41-
filename: `document.graphql`,
42-
text: item.content,
43-
lineOffset: item.loc.start.line - 1,
44-
offset: item.start + 1,
45-
});
46-
}
39+
if (extractedDocuments && extractedDocuments.length > 0) {
40+
for (const item of extractedDocuments) {
41+
blocks.push({
42+
filename: `document.graphql`,
43+
text: item.content,
44+
lineOffset: item.loc.start.line - 1,
45+
offset: item.start + 1,
46+
});
47+
}
4748

48-
blocks.push(originalFileBlock);
49+
blocks.push(originalFileBlock);
4950

50-
return blocks;
51+
return blocks;
52+
}
53+
} catch (e) {
54+
// eslint-disable-next-line no-console
55+
console.warn(`[graphql-eslint/processor]: Unable to process file "${filename}": `, e);
5156
}
5257
}
5358

0 commit comments

Comments
 (0)