6
6
import { asArray } from '@graphql-tools/utils' ;
7
7
import { GraphQLConfig } from 'graphql-config' ;
8
8
import { loadOnDiskGraphQLConfig } from './graphql-config.js' ;
9
+ import { REPORT_ON_FIRST_CHARACTER } from './utils.js' ;
9
10
10
11
export type Block = Linter . ProcessorFile & {
11
12
lineOffset : number ;
@@ -58,19 +59,20 @@ export const processor: Linter.Processor<Block | string> = {
58
59
skipIndent : true ,
59
60
...pluckConfig ,
60
61
} ) ;
61
- const isSvelte = filePath . endsWith ( '.svelte' ) ;
62
62
63
63
const blocks : Block [ ] = sources . map ( item => ( {
64
64
filename : 'document.graphql' ,
65
65
text : item . body ,
66
- lineOffset : item . locationOffset . line - ( isSvelte ? 3 : 1 ) ,
66
+ lineOffset : item . locationOffset . line - 1 ,
67
67
// @ts -expect-error -- `index` field exist but show ts error
68
- offset : item . locationOffset . index + ( isSvelte ? - 52 : 1 ) ,
68
+ offset : item . locationOffset . index + 1 ,
69
69
} ) ) ;
70
70
blocksMap . set ( filePath , blocks ) ;
71
71
72
72
return [ ...blocks , code /* source code must be provided and be last */ ] ;
73
- } catch {
73
+ } catch ( e ) {
74
+ // eslint-disable-next-line no-console
75
+ console . error ( e ) ;
74
76
// in case of parsing error return code as is
75
77
return [ code ] ;
76
78
}
@@ -80,7 +82,19 @@ export const processor: Linter.Processor<Block | string> = {
80
82
for ( let i = 0 ; i < blocks . length ; i += 1 ) {
81
83
const { lineOffset, offset } = blocks [ i ] ;
82
84
83
- for ( const message of messages [ i ] ) {
85
+ for ( const message of messages [ i ] || [ ] ) {
86
+ const isVueOrSvelte = / \. ( v u e | s v e l t e ) $ / . test ( filePath ) ;
87
+ if ( isVueOrSvelte ) {
88
+ // We can't show correct report location because after processing with
89
+ // graphql-tag-pluck location is incorrect, disable fixes as well
90
+ delete message . endLine ;
91
+ delete message . endColumn ;
92
+ delete message . fix ;
93
+ delete message . suggestions ;
94
+ Object . assign ( message , REPORT_ON_FIRST_CHARACTER ) ;
95
+ continue ;
96
+ }
97
+
84
98
message . line += lineOffset ;
85
99
// endLine can not exist if only `loc: { start, column }` was provided to context.report
86
100
if ( typeof message . endLine === 'number' ) {
0 commit comments