1
1
import { TSESTree } from '@typescript-eslint/experimental-utils' ;
2
2
import * as util from '../util' ;
3
3
4
- type MessageIds = 'unsafeCall' | 'unsafeNew' ;
4
+ type MessageIds = 'unsafeCall' | 'unsafeNew' | 'unsafeTemplateTag' ;
5
5
6
6
export default util . createRule < [ ] , MessageIds > ( {
7
7
name : 'no-unsafe-call' ,
@@ -16,6 +16,7 @@ export default util.createRule<[], MessageIds>({
16
16
messages : {
17
17
unsafeCall : 'Unsafe call of an any typed value' ,
18
18
unsafeNew : 'Unsafe construction of an any type value' ,
19
+ unsafeTemplateTag : 'Unsafe any typed template tag' ,
19
20
} ,
20
21
schema : [ ] ,
21
22
} ,
@@ -25,14 +26,11 @@ export default util.createRule<[], MessageIds>({
25
26
const checker = program . getTypeChecker ( ) ;
26
27
27
28
function checkCall (
28
- node :
29
- | TSESTree . CallExpression
30
- | TSESTree . OptionalCallExpression
31
- | TSESTree . NewExpression ,
32
- reportingNode : TSESTree . Expression = node . callee ,
33
- messageId : MessageIds = 'unsafeCall' ,
29
+ node : TSESTree . Node ,
30
+ reportingNode : TSESTree . Node ,
31
+ messageId : MessageIds ,
34
32
) : void {
35
- const tsNode = esTreeNodeToTSNodeMap . get ( node . callee ) ;
33
+ const tsNode = esTreeNodeToTSNodeMap . get ( node ) ;
36
34
const type = checker . getTypeAtLocation ( tsNode ) ;
37
35
if ( util . isTypeAnyType ( type ) ) {
38
36
context . report ( {
@@ -43,9 +41,16 @@ export default util.createRule<[], MessageIds>({
43
41
}
44
42
45
43
return {
46
- 'CallExpression, OptionalCallExpression' : checkCall ,
44
+ 'CallExpression, OptionalCallExpression' (
45
+ node : TSESTree . CallExpression | TSESTree . OptionalCallExpression ,
46
+ ) : void {
47
+ checkCall ( node . callee , node . callee , 'unsafeCall' ) ;
48
+ } ,
47
49
NewExpression ( node ) : void {
48
- checkCall ( node , node , 'unsafeNew' ) ;
50
+ checkCall ( node . callee , node , 'unsafeNew' ) ;
51
+ } ,
52
+ 'TaggedTemplateExpression > *.tag' ( node : TSESTree . Node ) : void {
53
+ checkCall ( node , node , 'unsafeTemplateTag' ) ;
49
54
} ,
50
55
} ;
51
56
} ,
0 commit comments