Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds try/catch to the ESLint processor preprocess task #1093

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
43 changes: 24 additions & 19 deletions packages/plugin/src/processor.ts
Expand Up @@ -12,27 +12,32 @@ const blocksMap = new Map<string, Block[]>();
export const processor: Linter.Processor<Block | string> = {
supportsAutofix: true,
preprocess(code, filePath) {
if (RELEVANT_KEYWORDS.every(keyword => !code.includes(keyword))) {
return [code];
}
const extractedDocuments = parseCode({
code,
filePath,
options: {
globalGqlIdentifierName: ['gql', 'graphql'],
skipIndent: true,
},
});
try {
if (RELEVANT_KEYWORDS.every(keyword => !code.includes(keyword))) {
return [code];
}
const extractedDocuments = parseCode({
code,
filePath,
options: {
globalGqlIdentifierName: ['gql', 'graphql'],
skipIndent: true,
},
});

const blocks: Block[] = extractedDocuments.map(item => ({
filename: 'document.graphql',
text: item.content,
lineOffset: item.loc.start.line - 1,
offset: item.start + 1,
}));
blocksMap.set(filePath, blocks);
const blocks: Block[] = extractedDocuments.map(item => ({
filename: 'document.graphql',
text: item.content,
lineOffset: item.loc.start.line - 1,
offset: item.start + 1,
}));
blocksMap.set(filePath, blocks);

return [...blocks, code /* source code must be provided and be last */];
return [...blocks, code /* source code must be provided and be last */];
} catch {
// Bail and return original code if error is thrown.
return [code];
}
},
postprocess(messages, filePath) {
const blocks = blocksMap.get(filePath) || [];
Expand Down