Skip to content

Commit

Permalink
Fix processor compatibility with other plugins (#225)
Browse files Browse the repository at this point in the history
* Fix processor compatibility with other plugins

* added changeset

Co-authored-by: Dotan Simha <dotansimha@gmail.com>
  • Loading branch information
EmrysMyrddin and dotansimha committed Dec 19, 2020
1 parent 72e03b2 commit 937b322
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .changeset/shaggy-planets-travel.md
@@ -0,0 +1,5 @@
---
'@graphql-eslint/eslint-plugin': patch
---

Fix processor compatibility with other plugins
10 changes: 8 additions & 2 deletions packages/plugin/src/processors/code-files.ts
@@ -1,4 +1,5 @@
import { parseCode } from '@graphql-tools/graphql-tag-pluck';
import { basename } from 'path';

const RELEVANT_KEYWORDS = ['gql', 'graphql', '/* GraphQL */'];

Expand All @@ -19,6 +20,11 @@ export function createGraphqlProcessor() {
const blocks: Block[] = [];
blocksMap.set(filename, blocks);

// 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)}` }

if (filename && text && RELEVANT_KEYWORDS.some(keyword => text.includes(keyword))) {
const extractedDocuments = parseCode({
code: text,
Expand All @@ -39,13 +45,13 @@ export function createGraphqlProcessor() {
});
}

blocks.push({ text, filename });
blocks.push(originalFileBlock);

return blocks;
}
}

return [{ text, filename }];
return [originalFileBlock];
},
postprocess: (messageLists: any[], filename: string): any[] => {
const blocks = blocksMap.get(filename);
Expand Down

0 comments on commit 937b322

Please sign in to comment.