@@ -2,7 +2,13 @@ import { ASTKindToNode, Kind, TokenKind } from 'graphql';
22import { getRootTypeNames } from '@graphql-tools/utils' ;
33import { GraphQLESTreeNode } from '../../estree-converter/index.js' ;
44import { GraphQLESLintRule , ValueOf } from '../../types.js' ;
5- import { getLocation , getNodeName , requireGraphQLSchema , TYPES_KINDS } from '../../utils.js' ;
5+ import {
6+ ARRAY_DEFAULT_OPTIONS , eslintSelectorsTip ,
7+ getLocation ,
8+ getNodeName ,
9+ requireGraphQLSchema ,
10+ TYPES_KINDS
11+ } from "../../utils.js" ;
612
713export const RULE_ID = 'require-description' ;
814
@@ -30,18 +36,25 @@ const schema = {
3036 properties : {
3137 types : {
3238 type : 'boolean' ,
39+ enum : [ true ] ,
3340 description : `Includes:\n${ TYPES_KINDS . map ( kind => `- \`${ kind } \`` ) . join ( '\n' ) } ` ,
3441 } ,
3542 rootField : {
3643 type : 'boolean' ,
44+ enum : [ true ] ,
3745 description : 'Definitions within `Query`, `Mutation`, and `Subscription` root types.' ,
3846 } ,
47+ ignoredSelectors : {
48+ ...ARRAY_DEFAULT_OPTIONS ,
49+ description : [ 'Ignore specific selectors' , eslintSelectorsTip ] . join ( '\n' )
50+ } ,
3951 ...Object . fromEntries (
4052 [ ...ALLOWED_KINDS ] . sort ( ) . map ( kind => {
41- let description = `Read more about this kind on [spec.graphql.org](https://spec.graphql.org/October2021/#${ kind } ).` ;
53+ let description = `> [!NOTE]
54+ >
55+ > Read more about this kind on [spec.graphql.org](https://spec.graphql.org/October2021/#${ kind } ).` ;
4256 if ( kind === Kind . OPERATION_DEFINITION ) {
43- description +=
44- '\n> You must use only comment syntax `#` and not description syntax `"""` or `"`.' ;
57+ description += [ '' , '' , '> [!WARNING]' , '>' , '> You must use only comment syntax `#` and not description syntax `"""` or `"`.' ] . join ( '\n' )
4558 }
4659 return [ kind , { type : 'boolean' , description } ] ;
4760 } ) ,
@@ -55,8 +68,9 @@ export type RuleOptions = [
5568 {
5669 [ key in AllowedKind ] ?: boolean ;
5770 } & {
58- types ?: boolean ;
59- rootField ?: boolean ;
71+ types ?: true ;
72+ rootField ?: true ;
73+ ignoredSelectors ?: string [ ] ;
6074 } ,
6175] ;
6276
@@ -132,7 +146,7 @@ export const rule: GraphQLESLintRule<RuleOptions> = {
132146 schema,
133147 } ,
134148 create ( context ) {
135- const { types, rootField, ...restOptions } = context . options [ 0 ] || { } ;
149+ let { types, rootField, ignoredSelectors = [ ] , ...restOptions } = context . options [ 0 ] || { } ;
136150
137151 const kinds = new Set < string > ( types ? TYPES_KINDS : [ ] ) ;
138152 for ( const [ kind , isEnabled ] of Object . entries ( restOptions ) ) {
@@ -152,13 +166,10 @@ export const rule: GraphQLESLintRule<RuleOptions> = {
152166 ] . join ( ',' ) } )$/] > FieldDefinition`,
153167 ) ;
154168 }
155-
156- if ( ! kinds . size ) {
157- throw new Error ( 'At least one kind must be enabled' ) ;
169+ let selector = `:matches( ${ [ ... kinds ] } )` ;
170+ for ( const str of ignoredSelectors ) {
171+ selector += `:not( ${ str } )`
158172 }
159-
160- const selector = [ ...kinds ] . join ( ',' ) ;
161-
162173 return {
163174 [ selector ] ( node : SelectorNode ) {
164175 let description = '' ;
0 commit comments