@@ -19,18 +19,60 @@ export default iterateJsdoc(({
19
19
const templateTags = utils . getTags ( 'template' ) ;
20
20
21
21
const usedNames = new Set ( ) ;
22
+ /**
23
+ * @param {string } potentialType
24
+ */
25
+ const checkForUsedTypes = ( potentialType ) => {
26
+ let parsedType ;
27
+ try {
28
+ parsedType = mode === 'permissive' ?
29
+ tryParseType ( /** @type {string } */ ( potentialType ) ) :
30
+ parseType ( /** @type {string } */ ( potentialType ) , mode ) ;
31
+ } catch {
32
+ return ;
33
+ }
34
+
35
+ traverse ( parsedType , ( nde ) => {
36
+ const {
37
+ type,
38
+ value,
39
+ } = /** @type {import('jsdoc-type-pratt-parser').NameResult } */ ( nde ) ;
40
+ if ( type === 'JsdocTypeName' && ( / ^ [ A - Z ] $ / ) . test ( value ) ) {
41
+ usedNames . add ( value ) ;
42
+ }
43
+ } ) ;
44
+ } ;
45
+
22
46
/**
23
47
* @param {import('@typescript-eslint/types').TSESTree.FunctionDeclaration|
24
48
* import('@typescript-eslint/types').TSESTree.ClassDeclaration|
25
49
* import('@typescript-eslint/types').TSESTree.TSInterfaceDeclaration|
26
50
* import('@typescript-eslint/types').TSESTree.TSTypeAliasDeclaration} aliasDeclaration
51
+ * @param {boolean } [checkParamsAndReturns]
27
52
*/
28
- const checkParameters = ( aliasDeclaration ) => {
53
+ const checkParameters = ( aliasDeclaration , checkParamsAndReturns ) => {
29
54
/* c8 ignore next -- Guard */
30
55
const { params} = aliasDeclaration . typeParameters ?? { params : [ ] } ;
31
56
for ( const { name : { name} } of params ) {
32
57
usedNames . add ( name ) ;
33
58
}
59
+ if ( checkParamsAndReturns ) {
60
+ const paramName = /** @type {string } */ ( utils . getPreferredTagName ( {
61
+ tagName : 'param' ,
62
+ } ) ) ;
63
+ const paramTags = utils . getTags ( paramName ) ;
64
+ for ( const paramTag of paramTags ) {
65
+ checkForUsedTypes ( paramTag . type ) ;
66
+ }
67
+
68
+ const returnsName = /** @type {string } */ ( utils . getPreferredTagName ( {
69
+ tagName : 'returns' ,
70
+ } ) ) ;
71
+ const returnsTags = utils . getTags ( returnsName ) ;
72
+ for ( const returnsTag of returnsTags ) {
73
+ checkForUsedTypes ( returnsTag . type ) ;
74
+ }
75
+ }
34
76
for ( const tag of templateTags ) {
35
77
const { name} = tag ;
36
78
const names = name . split ( / , \s * / ) ;
@@ -53,16 +95,20 @@ export default iterateJsdoc(({
53
95
case 'ExportDefaultDeclaration' :
54
96
case 'ExportNamedDeclaration' :
55
97
switch ( nde . declaration ?. type ) {
56
- case 'ClassDeclaration' :
57
98
case 'FunctionDeclaration' :
99
+ checkParameters ( nde . declaration , true ) ;
100
+ break ;
101
+ case 'ClassDeclaration' :
58
102
case 'TSTypeAliasDeclaration' :
59
103
case 'TSInterfaceDeclaration' :
60
104
checkParameters ( nde . declaration ) ;
61
105
break ;
62
106
}
63
107
break ;
64
- case 'ClassDeclaration' :
65
108
case 'FunctionDeclaration' :
109
+ checkParameters ( nde , true ) ;
110
+ break ;
111
+ case 'ClassDeclaration' :
66
112
case 'TSTypeAliasDeclaration' :
67
113
case 'TSInterfaceDeclaration' :
68
114
checkParameters ( nde ) ;
@@ -76,37 +122,13 @@ export default iterateJsdoc(({
76
122
return ;
77
123
}
78
124
79
- /**
80
- * @param {string } potentialType
81
- */
82
- const checkForUsedTypes = ( potentialType ) => {
83
- let parsedType ;
84
- try {
85
- parsedType = mode === 'permissive' ?
86
- tryParseType ( /** @type {string } */ ( potentialType ) ) :
87
- parseType ( /** @type {string } */ ( potentialType ) , mode ) ;
88
- } catch {
89
- return ;
90
- }
91
-
92
- traverse ( parsedType , ( nde ) => {
93
- const {
94
- type,
95
- value,
96
- } = /** @type {import('jsdoc-type-pratt-parser').NameResult } */ ( nde ) ;
97
- if ( type === 'JsdocTypeName' && ( / ^ [ A - Z ] $ / ) . test ( value ) ) {
98
- usedNames . add ( value ) ;
99
- }
100
- } ) ;
101
- } ;
102
-
103
125
const potentialTypedefType = typedefTags [ 0 ] . type ;
104
126
checkForUsedTypes ( potentialTypedefType ) ;
105
127
106
- const tagName = /** @type {string } */ ( utils . getPreferredTagName ( {
128
+ const propertyName = /** @type {string } */ ( utils . getPreferredTagName ( {
107
129
tagName : 'property' ,
108
130
} ) ) ;
109
- const propertyTags = utils . getTags ( tagName ) ;
131
+ const propertyTags = utils . getTags ( propertyName ) ;
110
132
for ( const propertyTag of propertyTags ) {
111
133
checkForUsedTypes ( propertyTag . type ) ;
112
134
}
0 commit comments