@@ -12,6 +12,10 @@ import {
1212} from '../util' ;
1313
1414export type MessageIds =
15+ | 'errorCall'
16+ | 'errorCallThis'
17+ | 'errorNew'
18+ | 'errorTemplateTag'
1519 | 'unsafeCall'
1620 | 'unsafeCallThis'
1721 | 'unsafeNew'
@@ -27,13 +31,18 @@ export default createRule<[], MessageIds>({
2731 requiresTypeChecking : true ,
2832 } ,
2933 messages : {
30- unsafeCall : 'Unsafe call of a(n) {{type}} typed value.' ,
34+ errorCall : 'Unsafe call of a type that could not be resolved.' ,
35+ errorCallThis : 'Unsafe call of a `this` type that could not be resolved.' ,
36+ errorNew : 'Unsafe construction of a type that could not be resolved.' ,
37+ errorTemplateTag :
38+ 'Unsafe use of a template tag whose type could not be resolved.' ,
39+ unsafeCall : 'Unsafe call of {{type}} typed value.' ,
3140 unsafeCallThis : [
32- 'Unsafe call of a(n) {{type}} typed value. `this` is typed as {{type}}.' ,
41+ 'Unsafe call of {{type}} typed value. `this` is typed as {{type}}.' ,
3342 'You can try to fix this by turning on the `noImplicitThis` compiler option, or adding a `this` parameter to the function.' ,
3443 ] . join ( '\n' ) ,
35- unsafeNew : 'Unsafe construction of a(n) {{type}} typed value.' ,
36- unsafeTemplateTag : 'Unsafe use of a(n) {{type}} typed template tag.' ,
44+ unsafeNew : 'Unsafe construction of {{type}} typed value.' ,
45+ unsafeTemplateTag : 'Unsafe use of {{type}} typed template tag.' ,
3746 } ,
3847 schema : [ ] ,
3948 } ,
@@ -49,7 +58,8 @@ export default createRule<[], MessageIds>({
4958 function checkCall (
5059 node : TSESTree . Node ,
5160 reportingNode : TSESTree . Node ,
52- messageId : MessageIds ,
61+ unsafeMessageId : Extract < MessageIds , `unsafe${string } `> ,
62+ errorMessageId : Extract < MessageIds , `error${string } `> ,
5363 ) : void {
5464 const type = getConstrainedTypeAtLocation ( services , node ) ;
5565
@@ -63,17 +73,18 @@ export default createRule<[], MessageIds>({
6373 getConstrainedTypeAtLocation ( services , thisExpression ) ,
6474 )
6575 ) {
66- messageId = 'unsafeCallThis' ;
76+ unsafeMessageId = 'unsafeCallThis' ;
77+ errorMessageId = 'errorCallThis' ;
6778 }
6879 }
6980
7081 const isErrorType = tsutils . isIntrinsicErrorType ( type ) ;
7182
7283 context . report ( {
7384 node : reportingNode ,
74- messageId,
85+ messageId : isErrorType ? errorMessageId : unsafeMessageId ,
7586 data : {
76- type : isErrorType ? '`error` type' : ' `any`',
87+ type : 'an `any`',
7788 } ,
7889 } ) ;
7990 return ;
@@ -98,7 +109,7 @@ export default createRule<[], MessageIds>({
98109 }
99110
100111 const callSignatures = type . getCallSignatures ( ) ;
101- if ( messageId === 'unsafeNew' ) {
112+ if ( unsafeMessageId === 'unsafeNew' ) {
102113 if (
103114 callSignatures . some (
104115 signature =>
@@ -113,9 +124,9 @@ export default createRule<[], MessageIds>({
113124
114125 context . report ( {
115126 node : reportingNode ,
116- messageId,
127+ messageId : unsafeMessageId ,
117128 data : {
118- type : '`Function`' ,
129+ type : 'a `Function`' ,
119130 } ,
120131 } ) ;
121132 return ;
@@ -126,13 +137,13 @@ export default createRule<[], MessageIds>({
126137 'CallExpression > *.callee' (
127138 node : TSESTree . CallExpression [ 'callee' ] ,
128139 ) : void {
129- checkCall ( node , node , 'unsafeCall' ) ;
140+ checkCall ( node , node , 'unsafeCall' , 'errorCall' ) ;
130141 } ,
131142 NewExpression ( node ) : void {
132- checkCall ( node . callee , node , 'unsafeNew' ) ;
143+ checkCall ( node . callee , node , 'unsafeNew' , 'errorNew' ) ;
133144 } ,
134145 'TaggedTemplateExpression > *.tag' ( node : TSESTree . Node ) : void {
135- checkCall ( node , node , 'unsafeTemplateTag' ) ;
146+ checkCall ( node , node , 'unsafeTemplateTag' , 'errorTemplateTag' ) ;
136147 } ,
137148 } ;
138149 } ,
0 commit comments