1
1
import { GraphQLESLintRule } from '../types' ;
2
2
import { valueFromNode } from '../estree-parser/utils' ;
3
+ import { getLocation } from '../utils' ;
3
4
4
5
const DATE_REGEX = / ^ \d { 2 } \/ \d { 2 } \/ \d { 4 } $ / ;
5
6
@@ -47,10 +48,10 @@ const rule: GraphQLESLintRule<[{ argumentName?: string }]> = {
47
48
] ,
48
49
} ,
49
50
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' ,
54
55
} ,
55
56
schema : [
56
57
{
@@ -71,14 +72,17 @@ const rule: GraphQLESLintRule<[{ argumentName?: string }]> = {
71
72
const deletionDateNode = node . arguments . find ( arg => arg . name . value === argName ) ;
72
73
73
74
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
+ } ) ;
75
79
return ;
76
80
}
77
81
const deletionDate = valueFromNode ( deletionDateNode . value ) ;
78
82
const isValidDate = DATE_REGEX . test ( deletionDate ) ;
79
83
80
84
if ( ! isValidDate ) {
81
- context . report ( { node : node . name , messageId : MESSAGE_INVALID_FORMAT } ) ;
85
+ context . report ( { node : deletionDateNode . value , messageId : MESSAGE_INVALID_FORMAT } ) ;
82
86
return ;
83
87
}
84
88
let [ day , month , year ] = deletionDate . split ( '/' ) ;
@@ -88,7 +92,7 @@ const rule: GraphQLESLintRule<[{ argumentName?: string }]> = {
88
92
89
93
if ( Number . isNaN ( deletionDateInMS ) ) {
90
94
context . report ( {
91
- node : node . name ,
95
+ node : deletionDateNode . value ,
92
96
messageId : MESSAGE_INVALID_DATE ,
93
97
data : {
94
98
deletionDate,
@@ -101,7 +105,7 @@ const rule: GraphQLESLintRule<[{ argumentName?: string }]> = {
101
105
102
106
if ( canRemove ) {
103
107
context . report ( {
104
- node : node . name ,
108
+ node,
105
109
messageId : MESSAGE_CAN_BE_REMOVED ,
106
110
data : {
107
111
nodeName : node . parent . name . value ,
0 commit comments