Skip to content

Commit

Permalink
Fix issues with processor parsing errors breaking the eslint execution
Browse files Browse the repository at this point in the history
  • Loading branch information
dotansimha committed Dec 24, 2020
1 parent aeb4ae1 commit a5e1e6e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 20 deletions.
5 changes: 5 additions & 0 deletions .changeset/little-steaks-punch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-eslint/eslint-plugin': patch
---

Fix issues with processor parsing errors breaking the eslint execution
45 changes: 25 additions & 20 deletions packages/plugin/src/processors/code-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,36 @@ export function createGraphqlProcessor() {
// WORKAROUND: This restores the original filename for the block representing original code.
// This allows to be compatible with other eslint plugins relying on filesystem
// This is temporary, waiting for https://github.com/eslint/eslint/issues/11989
const originalFileBlock = { text, filename: `/../../${basename(filename)}` }
const originalFileBlock = { text, filename: `/../../${basename(filename)}` };

if (filename && text && RELEVANT_KEYWORDS.some(keyword => text.includes(keyword))) {
const extractedDocuments = parseCode({
code: text,
filePath: filename,
options: {
globalGqlIdentifierName: ['gql', 'graphql'],
skipIndent: true,
},
});
try {
const extractedDocuments = parseCode({
code: text,
filePath: filename,
options: {
globalGqlIdentifierName: ['gql', 'graphql'],
skipIndent: true,
},
});

if (extractedDocuments && extractedDocuments.length > 0) {
for (const item of extractedDocuments) {
blocks.push({
filename: `document.graphql`,
text: item.content,
lineOffset: item.loc.start.line - 1,
offset: item.start + 1,
});
}
if (extractedDocuments && extractedDocuments.length > 0) {
for (const item of extractedDocuments) {
blocks.push({
filename: `document.graphql`,
text: item.content,
lineOffset: item.loc.start.line - 1,
offset: item.start + 1,
});
}

blocks.push(originalFileBlock);
blocks.push(originalFileBlock);

return blocks;
return blocks;
}
} catch (e) {
// eslint-disable-next-line no-console
console.warn(`[graphql-eslint/processor]: Unable to process file "${filename}": `, e);
}
}

Expand Down

0 comments on commit a5e1e6e

Please sign in to comment.