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