1- /* eslint-disable @typescript-eslint/no-var-requires */
21import { AST } from 'eslint' ;
32import { Comment , SourceLocation } from 'estree' ;
43import {
@@ -25,40 +24,14 @@ export function getBaseType(type: GraphQLOutputType): GraphQLNamedType {
2524 return type ;
2625}
2726
28- // Hardcoded type because tests fails on graphql 15
29- type TokenKindValue =
30- | ':'
31- | '!'
32- | '...'
33- | '('
34- | ')'
35- | '['
36- | ']'
37- | '{'
38- | '}'
39- | '@'
40- | '&'
41- // | '<EOF>'
42- | '<SOF>'
43- | '='
44- | '|'
45- | '$'
46- | 'BlockString'
47- | 'Comment'
48- | 'Float'
49- | 'Int'
50- | 'Name'
51- | 'String' ;
52-
53- export function convertToken < T extends TokenKindValue | 'Block' | 'Line' > (
27+ export function convertToken < T extends TokenKind | 'Block' | 'Line' > (
5428 token : Token ,
5529 type : T ,
5630) : Omit < AST . Token , 'type' > & { type : T } {
5731 const { line, column, end, start, value } = token ;
5832 return {
5933 type,
60- // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion -- TODO: remove `!` when drop support of graphql@15
61- value : value ! ,
34+ value,
6235 /*
6336 * ESLint has 0-based column number
6437 * https://eslint.org/docs/developer-guide/working-with-rules#contextreport
@@ -77,25 +50,9 @@ export function convertToken<T extends TokenKindValue | 'Block' | 'Line'>(
7750 } ;
7851}
7952
80- function getLexer ( source : Source ) : Lexer {
81- // GraphQL v14
82- const gqlLanguage = require ( 'graphql/language' ) ;
83- if ( gqlLanguage ?. createLexer ) {
84- return gqlLanguage . createLexer ( source , { } ) ;
85- }
86-
87- // GraphQL v15
88- const { Lexer : LexerCls } = require ( 'graphql' ) ;
89- if ( LexerCls && typeof LexerCls === 'function' ) {
90- return new LexerCls ( source ) ;
91- }
92-
93- throw new Error ( 'Unsupported GraphQL version! Please make sure to use GraphQL v14 or newer!' ) ;
94- }
95-
9653export function extractTokens ( filePath : string , code : string ) : AST . Token [ ] {
9754 const source = new Source ( code , filePath ) ;
98- const lexer = getLexer ( source ) ;
55+ const lexer = new Lexer ( source ) ;
9956 const tokens : AST . Token [ ] = [ ] ;
10057 let token = lexer . advance ( ) ;
10158
@@ -120,8 +77,7 @@ export function extractComments(loc?: Location): Comment[] {
12077 const comment = convertToken (
12178 token ,
12279 // `eslint-disable` directive works only with `Block` type comment
123- // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion -- TODO: remove `!` when drop support of graphql@15
124- token . value ! . trimStart ( ) . startsWith ( 'eslint' ) ? 'Block' : 'Line' ,
80+ token . value . trimStart ( ) . startsWith ( 'eslint' ) ? 'Block' : 'Line' ,
12581 ) ;
12682 comments . push ( comment ) ;
12783 }
0 commit comments