@lewishowles/lint-config 0.6.0 → 0.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/comments/utils/documentation.js +31 -10
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -157,11 +157,14 @@ function getObjectPatternPaths(sourceCode, node, parentPath) {
|
|
|
157
157
|
* The Oxlint source code object.
|
|
158
158
|
* @param {object} node
|
|
159
159
|
* The parameter node.
|
|
160
|
+
* @param {string} [rootPath]
|
|
161
|
+
* The documented name that starts each path for a destructured object
|
|
162
|
+
* parameter. Defaults to options.
|
|
160
163
|
*
|
|
161
164
|
* @returns {string[]}
|
|
162
165
|
* The required JSDoc parameter paths.
|
|
163
166
|
*/
|
|
164
|
-
function getParameterPaths(sourceCode, node) {
|
|
167
|
+
function getParameterPaths(sourceCode, node, rootPath = "options") {
|
|
165
168
|
if (node.type === "Identifier") {
|
|
166
169
|
return [node.name];
|
|
167
170
|
}
|
|
@@ -171,11 +174,11 @@ function getParameterPaths(sourceCode, node) {
|
|
|
171
174
|
}
|
|
172
175
|
|
|
173
176
|
if (node.type === "ObjectPattern") {
|
|
174
|
-
return getObjectPatternPaths(sourceCode, node,
|
|
177
|
+
return getObjectPatternPaths(sourceCode, node, rootPath);
|
|
175
178
|
}
|
|
176
179
|
|
|
177
180
|
if (node.type === "AssignmentPattern") {
|
|
178
|
-
return getParameterPaths(sourceCode, node.left);
|
|
181
|
+
return getParameterPaths(sourceCode, node.left, rootPath);
|
|
179
182
|
}
|
|
180
183
|
|
|
181
184
|
return [];
|
|
@@ -189,25 +192,40 @@ function getParameterPaths(sourceCode, node) {
|
|
|
189
192
|
* @param {object} comment
|
|
190
193
|
* The JSDoc comment token.
|
|
191
194
|
*
|
|
192
|
-
* @returns {
|
|
193
|
-
*
|
|
195
|
+
* @returns {object}
|
|
196
|
+
* An object with names, the set of every documented parameter path, and
|
|
197
|
+
* topLevelNames, the top-level names in the order they are documented.
|
|
194
198
|
*/
|
|
195
199
|
function getDocumentedParameters(sourceCode, comment) {
|
|
196
200
|
// Splits the JSDoc block into its individual lines.
|
|
197
201
|
const content = getJSDocContent(getCommentText(sourceCode, comment));
|
|
198
202
|
// Collects the parameter paths documented by @param tags.
|
|
199
203
|
const names = new Set();
|
|
204
|
+
// Collects top-level parameter names in their documented order.
|
|
205
|
+
const topLevelNames = [];
|
|
200
206
|
|
|
201
207
|
for (const line of content) {
|
|
202
208
|
// Matches an @param tag and captures its documented path.
|
|
203
209
|
const match = line.trim().match(/^@param(?:\s+\{[^}]+\})?\s+(\[[^\]]+\]|\S+)/);
|
|
204
210
|
|
|
205
211
|
if (match) {
|
|
206
|
-
|
|
212
|
+
// The documented name as written, including optional brackets and
|
|
213
|
+
// any default value.
|
|
214
|
+
const name = match[1];
|
|
215
|
+
|
|
216
|
+
names.add(name);
|
|
217
|
+
|
|
218
|
+
// Removes optional and default-value syntax before checking for a
|
|
219
|
+
// nested path.
|
|
220
|
+
const topLevelName = name.replace(/^\[|\]$/g, "").split("=")[0];
|
|
221
|
+
|
|
222
|
+
if (!topLevelName.includes(".")) {
|
|
223
|
+
topLevelNames.push(topLevelName);
|
|
224
|
+
}
|
|
207
225
|
}
|
|
208
226
|
}
|
|
209
227
|
|
|
210
|
-
return names;
|
|
228
|
+
return { names, topLevelNames };
|
|
211
229
|
}
|
|
212
230
|
|
|
213
231
|
/**
|
|
@@ -306,11 +324,14 @@ export function reportFunctionDocumentation(context, node, functionNode, options
|
|
|
306
324
|
}
|
|
307
325
|
|
|
308
326
|
// Reads the parameter paths already documented by @param tags.
|
|
309
|
-
const documentedParameters = getDocumentedParameters(
|
|
327
|
+
const { names: documentedParameters, topLevelNames } = getDocumentedParameters(
|
|
328
|
+
context.sourceCode,
|
|
329
|
+
comment,
|
|
330
|
+
);
|
|
310
331
|
|
|
311
332
|
// Derives the parameter paths the function actually requires.
|
|
312
|
-
const parameterPaths = functionNode.params.flatMap((parameter) =>
|
|
313
|
-
getParameterPaths(context.sourceCode, parameter),
|
|
333
|
+
const parameterPaths = functionNode.params.flatMap((parameter, index) =>
|
|
334
|
+
getParameterPaths(context.sourceCode, parameter, topLevelNames[index]),
|
|
314
335
|
);
|
|
315
336
|
|
|
316
337
|
for (const path of parameterPaths) {
|