@@ -18,39 +18,62 @@ export default iterateJsdoc(({
18
18
if ( utils . hasTag ( 'type' ) ) {
19
19
return ;
20
20
}
21
- const findExpectedIndex = ( jsdocTags , funcParmOrder , tagName ) => {
22
- const docTags = jsdocTags . filter ( ( { tag} ) => {
23
- return tag === tagName ;
21
+
22
+ const preferredTagName = utils . getPreferredTagName ( { tagName : 'param' } ) ;
23
+
24
+ const findExpectedIndex = ( jsdocTags , indexAtFunctionParams ) => {
25
+ const functionTags = jsdocTags . filter ( ( { tag} ) => {
26
+ return tag === preferredTagName ;
24
27
} ) ;
25
28
let expectedIndex = jsdocTags . length ;
26
- jsdocTags . forEach ( ( tag , idx ) => {
27
- if ( tag . tag === tagName ) {
28
- expectedIndex = docTags . indexOf ( tag ) < funcParmOrder ? idx + 1 : idx - 1 ;
29
+ jsdocTags . forEach ( ( tag , index ) => {
30
+ if ( tag . tag === preferredTagName ) {
31
+ expectedIndex = index ;
32
+ if ( functionTags . indexOf ( tag ) < indexAtFunctionParams ) {
33
+ expectedIndex += 1 ;
34
+ }
29
35
}
30
36
} ) ;
31
37
32
38
return expectedIndex ;
33
39
} ;
34
40
41
+ const missingTags = [ ] ;
42
+
35
43
functionParameterNames . forEach ( ( functionParameterName , functionParameterIdx ) => {
36
44
if ( [ '<ObjectPattern>' , '<ArrayPattern>' ] . includes ( functionParameterName ) ) {
37
45
return ;
38
46
}
39
47
if ( ! jsdocParameterNames . includes ( functionParameterName ) ) {
40
- const preferredTagName = utils . getPreferredTagName ( { tagName : 'param' } ) ;
41
- utils . reportJSDoc ( `Missing JSDoc @${ preferredTagName } "${ functionParameterName } " declaration.` , null , ( ) => {
42
- if ( ! jsdoc . tags ) {
43
- jsdoc . tags = [ ] ;
44
- }
45
-
46
- const expectedIdx = findExpectedIndex ( jsdoc . tags , functionParameterIdx , preferredTagName ) ;
47
- jsdoc . tags . splice ( expectedIdx , 0 , {
48
- name : functionParameterName ,
49
- tag : preferredTagName ,
50
- } ) ;
48
+ missingTags . push ( {
49
+ functionParameterIdx,
50
+ functionParameterName,
51
51
} ) ;
52
52
}
53
53
} ) ;
54
+
55
+ const fixAll = ( missings , tags ) => {
56
+ missings . forEach ( ( { functionParameterIdx, functionParameterName} ) => {
57
+ const expectedIdx = findExpectedIndex ( tags , functionParameterIdx ) ;
58
+ tags . splice ( expectedIdx , 0 , {
59
+ name : functionParameterName ,
60
+ tag : preferredTagName ,
61
+ } ) ;
62
+ } ) ;
63
+ } ;
64
+
65
+ missingTags . forEach ( ( { functionParameterName} , index ) => {
66
+ utils . reportJSDoc ( `Missing JSDoc @${ preferredTagName } "${ functionParameterName } " declaration.` , null , ( ) => {
67
+ if ( ! jsdoc . tags ) {
68
+ jsdoc . tags = [ ] ;
69
+ }
70
+
71
+ // Fix all missing tags at the first time.
72
+ if ( index === 0 ) {
73
+ fixAll ( missingTags , jsdoc . tags ) ;
74
+ }
75
+ } ) ;
76
+ } ) ;
54
77
} , {
55
78
meta : {
56
79
fixable : true ,
0 commit comments