66import { asArray } from '@graphql-tools/utils' ;
77import { GraphQLConfig } from 'graphql-config' ;
88import { loadOnDiskGraphQLConfig } from './graphql-config.js' ;
9+ import { REPORT_ON_FIRST_CHARACTER } from './utils.js' ;
910
1011export type Block = Linter . ProcessorFile & {
1112 lineOffset : number ;
@@ -58,19 +59,20 @@ export const processor: Linter.Processor<Block | string> = {
5859 skipIndent : true ,
5960 ...pluckConfig ,
6061 } ) ;
61- const isSvelte = filePath . endsWith ( '.svelte' ) ;
6262
6363 const blocks : Block [ ] = sources . map ( item => ( {
6464 filename : 'document.graphql' ,
6565 text : item . body ,
66- lineOffset : item . locationOffset . line - ( isSvelte ? 3 : 1 ) ,
66+ lineOffset : item . locationOffset . line - 1 ,
6767 // @ts -expect-error -- `index` field exist but show ts error
68- offset : item . locationOffset . index + ( isSvelte ? - 52 : 1 ) ,
68+ offset : item . locationOffset . index + 1 ,
6969 } ) ) ;
7070 blocksMap . set ( filePath , blocks ) ;
7171
7272 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 ) ;
7476 // in case of parsing error return code as is
7577 return [ code ] ;
7678 }
@@ -80,7 +82,19 @@ export const processor: Linter.Processor<Block | string> = {
8082 for ( let i = 0 ; i < blocks . length ; i += 1 ) {
8183 const { lineOffset, offset } = blocks [ i ] ;
8284
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+
8498 message . line += lineOffset ;
8599 // endLine can not exist if only `loc: { start, column }` was provided to context.report
86100 if ( typeof message . endLine === 'number' ) {
0 commit comments