File tree 2 files changed +50
-4
lines changed
2 files changed +50
-4
lines changed Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ function removeSpaces(str: string): string {
28
28
return str . replace ( / / g, '' ) ;
29
29
}
30
30
31
- function stringifyTypeName (
31
+ function stringifyNode (
32
32
node : TSESTree . Node ,
33
33
sourceCode : TSESLint . SourceCode ,
34
34
) : string {
@@ -175,7 +175,7 @@ export default util.createRule<Options, MessageIds>({
175
175
176
176
function checkBannedTypes (
177
177
typeNode : TSESTree . Node ,
178
- name = stringifyTypeName ( typeNode , context . getSourceCode ( ) ) ,
178
+ name = stringifyNode ( typeNode , context . getSourceCode ( ) ) ,
179
179
) : void {
180
180
const bannedType = bannedTypes . get ( name ) ;
181
181
@@ -223,8 +223,12 @@ export default util.createRule<Options, MessageIds>({
223
223
224
224
checkBannedTypes ( node ) ;
225
225
} ,
226
- TSTypeReference ( { typeName } ) : void {
227
- checkBannedTypes ( typeName ) ;
226
+ TSTypeReference ( node ) : void {
227
+ checkBannedTypes ( node . typeName ) ;
228
+
229
+ if ( node . typeParameters ) {
230
+ checkBannedTypes ( node ) ;
231
+ }
228
232
} ,
229
233
} ;
230
234
} ,
Original file line number Diff line number Diff line change @@ -487,6 +487,48 @@ let bar: object = {};
487
487
} ,
488
488
] ,
489
489
} ,
490
+ {
491
+ code : 'type Foo = Bar<any>;' ,
492
+ errors : [
493
+ {
494
+ messageId : 'bannedTypeMessage' ,
495
+ data : {
496
+ name : 'Bar<any>' ,
497
+ customMessage : " Don't use `any` as a type parameter to `Bar`" ,
498
+ } ,
499
+ line : 1 ,
500
+ column : 12 ,
501
+ } ,
502
+ ] ,
503
+ options : [
504
+ {
505
+ types : {
506
+ 'Bar<any>' : "Don't use `any` as a type parameter to `Bar`" ,
507
+ } ,
508
+ } ,
509
+ ] ,
510
+ } ,
511
+ {
512
+ code : noFormat `type Foo = Bar<A,B>;` ,
513
+ errors : [
514
+ {
515
+ messageId : 'bannedTypeMessage' ,
516
+ data : {
517
+ name : 'Bar<A,B>' ,
518
+ customMessage : " Don't pass `A, B` as parameters to `Bar`" ,
519
+ } ,
520
+ line : 1 ,
521
+ column : 12 ,
522
+ } ,
523
+ ] ,
524
+ options : [
525
+ {
526
+ types : {
527
+ 'Bar<A, B>' : "Don't pass `A, B` as parameters to `Bar`" ,
528
+ } ,
529
+ } ,
530
+ ] ,
531
+ } ,
490
532
...objectReduceKey (
491
533
TYPE_KEYWORDS ,
492
534
( acc : TSESLint . InvalidTestCase < MessageIds , Options > [ ] , key ) => {
You can’t perform that action at this time.
0 commit comments