|
| 1 | +import _ from 'lodash'; |
1 | 2 | import iterateJsdoc from '../iterateJsdoc'; |
2 | 3 |
|
3 | 4 | type T = [string, () => T]; |
@@ -47,11 +48,14 @@ export default iterateJsdoc(({ |
47 | 48 | } |
48 | 49 |
|
49 | 50 | const { |
| 51 | + autoIncrementBase = 0, |
| 52 | + checkRestProperty = false, |
| 53 | + checkDestructured = true, |
| 54 | + checkTypesPattern = '/^(?:[oO]bject|[aA]rray|PlainObject|Generic(?:Object|Array))$/', |
50 | 55 | enableFixer = true, |
51 | 56 | enableRootFixer = true, |
52 | | - checkRestProperty = false, |
53 | 57 | enableRestElementFixer = true, |
54 | | - checkTypesPattern = '/^(?:[oO]bject|[aA]rray|PlainObject|Generic(?:Object|Array))$/', |
| 58 | + unnamedRootBase = ['root'], |
55 | 59 | } = context.options[0] || {}; |
56 | 60 |
|
57 | 61 | const lastSlashPos = checkTypesPattern.lastIndexOf('/'); |
@@ -93,10 +97,6 @@ export default iterateJsdoc(({ |
93 | 97 | return paramTags.length; |
94 | 98 | }; |
95 | 99 |
|
96 | | - const { |
97 | | - autoIncrementBase = 0, |
98 | | - unnamedRootBase = ['root'], |
99 | | - } = context.options[0] || {}; |
100 | 100 | let [nextRootName, incremented, namer] = rootNamer([...unnamedRootBase], autoIncrementBase); |
101 | 101 |
|
102 | 102 | functionParameterNames.forEach((functionParameterName, functionParameterIdx) => { |
@@ -125,32 +125,39 @@ export default iterateJsdoc(({ |
125 | 125 | } |
126 | 126 |
|
127 | 127 | names.forEach((paramName, idx) => { |
128 | | - if (jsdocParameterNames && !jsdocParameterNames.find(({name}) => { |
| 128 | + // Add root if the root name is not in the docs (and is not already |
| 129 | + // in the tags to be fixed) |
| 130 | + if (!jsdocParameterNames.find(({name}) => { |
129 | 131 | return name === rootName; |
| 132 | + }) && !missingTags.find(({functionParameterName: fpn}) => { |
| 133 | + return fpn === rootName; |
130 | 134 | })) { |
131 | | - if (!missingTags.find(({functionParameterName: fpn}) => { |
132 | | - return fpn === rootName; |
133 | | - })) { |
134 | | - const emptyParamIdx = jsdocParameterNames.findIndex(({name}) => { |
135 | | - return !name; |
136 | | - }); |
| 135 | + const emptyParamIdx = jsdocParameterNames.findIndex(({name}) => { |
| 136 | + return !name; |
| 137 | + }); |
137 | 138 |
|
138 | | - if (emptyParamIdx > -1) { |
139 | | - missingTags.push({ |
140 | | - functionParameterIdx: emptyParamIdx, |
141 | | - functionParameterName: rootName, |
142 | | - inc, |
143 | | - remove: true, |
144 | | - }); |
145 | | - } else { |
146 | | - missingTags.push({ |
147 | | - functionParameterIdx: paramIndex[rootName], |
148 | | - functionParameterName: rootName, |
149 | | - inc, |
150 | | - }); |
151 | | - } |
| 139 | + if (emptyParamIdx > -1) { |
| 140 | + missingTags.push({ |
| 141 | + functionParameterIdx: emptyParamIdx, |
| 142 | + functionParameterName: rootName, |
| 143 | + inc, |
| 144 | + remove: true, |
| 145 | + }); |
| 146 | + } else { |
| 147 | + missingTags.push({ |
| 148 | + functionParameterIdx: _.has(paramIndex, rootName) ? |
| 149 | + paramIndex[rootName] : |
| 150 | + paramIndex[paramName], |
| 151 | + functionParameterName: rootName, |
| 152 | + inc, |
| 153 | + }); |
152 | 154 | } |
153 | 155 | } |
| 156 | + |
| 157 | + if (!checkDestructured) { |
| 158 | + return; |
| 159 | + } |
| 160 | + |
154 | 161 | if (!checkRestProperty && rests[idx]) { |
155 | 162 | return; |
156 | 163 | } |
@@ -252,6 +259,9 @@ export default iterateJsdoc(({ |
252 | 259 | default: true, |
253 | 260 | type: 'boolean', |
254 | 261 | }, |
| 262 | + checkDestructured: { |
| 263 | + type: 'boolean', |
| 264 | + }, |
255 | 265 | checkGetters: { |
256 | 266 | default: false, |
257 | 267 | type: 'boolean', |
|
0 commit comments