1
- import { GraphQLESLintRule , GraphQLESLintRuleContext } from '../types' ;
1
+ import { GraphQLESLintRule , GraphQLESLintRuleContext , ValueOf } from '../types' ;
2
2
import { GraphQLESTreeNode } from '../estree-parser/estree-ast' ;
3
- import { ASTNode , Kind , StringValueNode } from 'graphql' ;
3
+ import { ASTKindToNode , Kind , StringValueNode } from 'graphql' ;
4
4
5
5
const REQUIRE_DESCRIPTION_ERROR = 'REQUIRE_DESCRIPTION_ERROR' ;
6
6
const DESCRIBABLE_NODES = [
@@ -17,23 +17,30 @@ const DESCRIBABLE_NODES = [
17
17
] ;
18
18
type RequireDescriptionRuleConfig = [ { on : typeof DESCRIBABLE_NODES } ] ;
19
19
20
+ type AllowedKind = typeof DESCRIBABLE_NODES [ number ] ;
21
+ type AllowedKindToNode = Pick < ASTKindToNode , AllowedKind > ;
22
+
20
23
function verifyRule (
21
24
context : GraphQLESLintRuleContext < RequireDescriptionRuleConfig > ,
22
- node : GraphQLESTreeNode < ASTNode > & {
25
+ node : GraphQLESTreeNode < ValueOf < AllowedKindToNode > > & {
23
26
readonly description ?: GraphQLESTreeNode < StringValueNode > ;
24
27
}
25
28
) {
26
29
if ( node ) {
27
30
if ( ! node . description || ! node . description . value || node . description . value . trim ( ) . length === 0 ) {
31
+ const { start, end } = ( 'name' in node ? node . name : node ) . loc ;
32
+
28
33
context . report ( {
29
34
loc : {
30
35
start : {
31
- line : node . loc . start . line ,
32
- column : node . loc . start . column - 1 ,
36
+ line : start . line ,
37
+ column : start . column - 1 ,
33
38
} ,
34
39
end : {
35
- line : node . loc . end . line ,
36
- column : node . loc . end . column ,
40
+ line : end . line ,
41
+ column :
42
+ // node.name don't exist on SchemaDefinition
43
+ 'name' in node ? end . column - 1 + node . name . value . length : end . column ,
37
44
} ,
38
45
} ,
39
46
messageId : REQUIRE_DESCRIPTION_ERROR ,
0 commit comments