11import { GraphQLESLintRule } from '../types' ;
22import { valueFromNode } from '../estree-parser/utils' ;
3+ import { getLocation } from '../utils' ;
34
45const DATE_REGEX = / ^ \d { 2 } \/ \d { 2 } \/ \d { 4 } $ / ;
56
@@ -47,10 +48,10 @@ const rule: GraphQLESLintRule<[{ argumentName?: string }]> = {
4748 ] ,
4849 } ,
4950 messages : {
50- [ MESSAGE_REQUIRE_DATE ] : 'Directive "@deprecated" must have a deletion date. ' ,
51- [ MESSAGE_INVALID_FORMAT ] : 'Deletion date must be in format "DD/MM/YYYY". ' ,
52- [ MESSAGE_INVALID_DATE ] : 'Invalid "{{ deletionDate }}" deletion date. ' ,
53- [ MESSAGE_CAN_BE_REMOVED ] : '"{{ nodeName }}" сan be removed. ' ,
51+ [ MESSAGE_REQUIRE_DATE ] : 'Directive "@deprecated" must have a deletion date' ,
52+ [ MESSAGE_INVALID_FORMAT ] : 'Deletion date must be in format "DD/MM/YYYY"' ,
53+ [ MESSAGE_INVALID_DATE ] : 'Invalid "{{ deletionDate }}" deletion date' ,
54+ [ MESSAGE_CAN_BE_REMOVED ] : '"{{ nodeName }}" сan be removed' ,
5455 } ,
5556 schema : [
5657 {
@@ -71,14 +72,17 @@ const rule: GraphQLESLintRule<[{ argumentName?: string }]> = {
7172 const deletionDateNode = node . arguments . find ( arg => arg . name . value === argName ) ;
7273
7374 if ( ! deletionDateNode ) {
74- context . report ( { node : node . name , messageId : MESSAGE_REQUIRE_DATE } ) ;
75+ context . report ( {
76+ loc : getLocation ( node . loc , node . name . value , { offsetEnd : 0 } ) ,
77+ messageId : MESSAGE_REQUIRE_DATE ,
78+ } ) ;
7579 return ;
7680 }
7781 const deletionDate = valueFromNode ( deletionDateNode . value ) ;
7882 const isValidDate = DATE_REGEX . test ( deletionDate ) ;
7983
8084 if ( ! isValidDate ) {
81- context . report ( { node : node . name , messageId : MESSAGE_INVALID_FORMAT } ) ;
85+ context . report ( { node : deletionDateNode . value , messageId : MESSAGE_INVALID_FORMAT } ) ;
8286 return ;
8387 }
8488 let [ day , month , year ] = deletionDate . split ( '/' ) ;
@@ -88,7 +92,7 @@ const rule: GraphQLESLintRule<[{ argumentName?: string }]> = {
8892
8993 if ( Number . isNaN ( deletionDateInMS ) ) {
9094 context . report ( {
91- node : node . name ,
95+ node : deletionDateNode . value ,
9296 messageId : MESSAGE_INVALID_DATE ,
9397 data : {
9498 deletionDate,
@@ -101,7 +105,7 @@ const rule: GraphQLESLintRule<[{ argumentName?: string }]> = {
101105
102106 if ( canRemove ) {
103107 context . report ( {
104- node : node . name ,
108+ node,
105109 messageId : MESSAGE_CAN_BE_REMOVED ,
106110 data : {
107111 nodeName : node . parent . name . value ,
0 commit comments