|
1 | 1 | import { Linter } from 'eslint'; |
2 | 2 | import { parseCode, GraphQLTagPluckOptions } from '@graphql-tools/graphql-tag-pluck'; |
3 | 3 | import { asArray } from '@graphql-tools/utils'; |
4 | | -import { loadGraphQLConfig } from './graphql-config'; |
| 4 | +import { GraphQLConfig } from 'graphql-config'; |
| 5 | +import { loadOnDiskGraphQLConfig } from './graphql-config'; |
5 | 6 |
|
6 | 7 | export type Block = Linter.ProcessorFile & { |
7 | 8 | lineOffset: number; |
8 | 9 | offset: number; |
9 | 10 | }; |
10 | 11 |
|
11 | | -let RELEVANT_KEYWORDS: string[]; |
12 | | -let graphQLTagPluckOptions: GraphQLTagPluckOptions; |
13 | | - |
14 | 12 | const blocksMap = new Map<string, Block[]>(); |
15 | 13 |
|
| 14 | +let onDiskConfig: GraphQLConfig; |
| 15 | + |
16 | 16 | export const processor: Linter.Processor<Block | string> = { |
17 | 17 | supportsAutofix: true, |
18 | 18 | preprocess(code, filePath) { |
19 | | - if (!RELEVANT_KEYWORDS) { |
20 | | - graphQLTagPluckOptions = loadGraphQLConfig().getDefault()?.extensions?.graphqlTagPluck; |
| 19 | + onDiskConfig ||= loadOnDiskGraphQLConfig(filePath); |
| 20 | + const graphQLTagPluckOptions: GraphQLTagPluckOptions = |
| 21 | + onDiskConfig?.getProjectForFile?.(filePath)?.extensions?.graphqlTagPluck; |
| 22 | + const { |
| 23 | + modules = [], |
| 24 | + globalGqlIdentifierName = ['gql', 'graphql'], |
| 25 | + gqlMagicComment = 'GraphQL', |
| 26 | + } = graphQLTagPluckOptions || {}; |
21 | 27 |
|
22 | | - const { |
23 | | - modules = [], |
24 | | - globalGqlIdentifierName = ['gql', 'graphql'], |
25 | | - gqlMagicComment = 'GraphQL', |
26 | | - } = graphQLTagPluckOptions || {}; |
27 | | - |
28 | | - RELEVANT_KEYWORDS = [ |
29 | | - ...new Set( |
30 | | - [ |
31 | | - ...modules.map(({ identifier }) => identifier), |
32 | | - ...asArray(globalGqlIdentifierName), |
33 | | - gqlMagicComment, |
34 | | - ].filter(Boolean) |
35 | | - ), |
36 | | - ]; |
37 | | - } |
| 28 | + const RELEVANT_KEYWORDS: string[] = [ |
| 29 | + ...new Set( |
| 30 | + [ |
| 31 | + ...modules.map(({ identifier }) => identifier), |
| 32 | + ...asArray(globalGqlIdentifierName), |
| 33 | + gqlMagicComment, |
| 34 | + ].filter(Boolean) |
| 35 | + ), |
| 36 | + ]; |
38 | 37 |
|
39 | 38 | if (RELEVANT_KEYWORDS.every(keyword => !code.includes(keyword))) { |
40 | 39 | return [code]; |
|
0 commit comments