mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
feat(11378): check param names in JSDoc (#47257)
This commit is contained in:
1 parent
954ce5b278
commit
b456702755
22 files changed
+779
-46
No files matched your search
+40
-33
@@ -34472,6 +34472,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
checkTypeParameters(getEffectiveTypeParameterDeclarations(node));
|
||||
checkUnmatchedJSDocParameters(node);
|
||||
|
||||
forEach(node.parameters, checkParameter);
|
||||
|
||||
@@ -36235,40 +36236,7 @@ namespace ts {
|
||||
|
||||
function checkJSDocParameterTag(node: JSDocParameterTag) {
|
||||
checkSourceElement(node.typeExpression);
|
||||
if (!getParameterSymbolFromJSDoc(node)) {
|
||||
const decl = getHostSignatureFromJSDoc(node);
|
||||
// don't issue an error for invalid hosts -- just functions --
|
||||
// and give a better error message when the host function mentions `arguments`
|
||||
// but the tag doesn't have an array type
|
||||
if (decl) {
|
||||
const i = getJSDocTags(decl).filter(isJSDocParameterTag).indexOf(node);
|
||||
if (i > -1 && i < decl.parameters.length && isBindingPattern(decl.parameters[i].name)) {
|
||||
return;
|
||||
}
|
||||
if (!containsArgumentsReference(decl)) {
|
||||
if (isQualifiedName(node.name)) {
|
||||
error(node.name,
|
||||
Diagnostics.Qualified_name_0_is_not_allowed_without_a_leading_param_object_1,
|
||||
entityNameToString(node.name),
|
||||
entityNameToString(node.name.left));
|
||||
}
|
||||
else {
|
||||
error(node.name,
|
||||
Diagnostics.JSDoc_param_tag_has_name_0_but_there_is_no_parameter_with_that_name,
|
||||
idText(node.name));
|
||||
}
|
||||
}
|
||||
else if (findLast(getJSDocTags(decl), isJSDocParameterTag) === node &&
|
||||
node.typeExpression && node.typeExpression.type &&
|
||||
!isArrayType(getTypeFromTypeNode(node.typeExpression.type))) {
|
||||
error(node.name,
|
||||
Diagnostics.JSDoc_param_tag_has_name_0_but_there_is_no_parameter_with_that_name_It_would_match_arguments_if_it_had_an_array_type,
|
||||
idText(node.name.kind === SyntaxKind.QualifiedName ? node.name.right : node.name));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function checkJSDocPropertyTag(node: JSDocPropertyTag) {
|
||||
checkSourceElement(node.typeExpression);
|
||||
}
|
||||
@@ -38564,6 +38532,45 @@ namespace ts {
|
||||
}
|
||||
}
|
||||
|
||||
function checkUnmatchedJSDocParameters(node: SignatureDeclaration) {
|
||||
const jsdocParameters = filter(getJSDocTags(node), isJSDocParameterTag);
|
||||
if (!length(jsdocParameters)) return;
|
||||
|
||||
const isJs = isInJSFile(node);
|
||||
const parameters = new Set<__String>();
|
||||
const excludedParameters = new Set<number>();
|
||||
forEach(node.parameters, ({ name }, index) => {
|
||||
if (isIdentifier(name)) {
|
||||
parameters.add(name.escapedText);
|
||||
}
|
||||
if (isBindingPattern(name)) {
|
||||
excludedParameters.add(index);
|
||||
}
|
||||
});
|
||||
|
||||
const containsArguments = containsArgumentsReference(node);
|
||||
if (containsArguments) {
|
||||
const lastJSDocParam = lastOrUndefined(jsdocParameters);
|
||||
if (lastJSDocParam && isIdentifier(lastJSDocParam.name) && lastJSDocParam.typeExpression &&
|
||||
lastJSDocParam.typeExpression.type && !parameters.has(lastJSDocParam.name.escapedText) && !isArrayType(getTypeFromTypeNode(lastJSDocParam.typeExpression.type))) {
|
||||
errorOrSuggestion(isJs, lastJSDocParam.name, Diagnostics.JSDoc_param_tag_has_name_0_but_there_is_no_parameter_with_that_name_It_would_match_arguments_if_it_had_an_array_type, idText(lastJSDocParam.name));
|
||||
}
|
||||
}
|
||||
else {
|
||||
forEach(jsdocParameters, ({ name }, index) => {
|
||||
if (excludedParameters.has(index) || isIdentifier(name) && parameters.has(name.escapedText)) {
|
||||
return;
|
||||
}
|
||||
if (isQualifiedName(name)) {
|
||||
errorOrSuggestion(isJs, name, Diagnostics.Qualified_name_0_is_not_allowed_without_a_leading_param_object_1, entityNameToString(name), entityNameToString(name.left));
|
||||
}
|
||||
else {
|
||||
errorOrSuggestion(isJs, name, Diagnostics.JSDoc_param_tag_has_name_0_but_there_is_no_parameter_with_that_name, idText(name));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check each type parameter and check that type parameters have no duplicate type parameter declarations
|
||||
*/
|
||||
|
||||
@@ -7135,6 +7135,18 @@
|
||||
"category": "Message",
|
||||
"code": 95170
|
||||
},
|
||||
"Delete unused '@param' tag '{0}'": {
|
||||
"category": "Message",
|
||||
"code": 95171
|
||||
},
|
||||
"Delete all unused '@param' tags": {
|
||||
"category": "Message",
|
||||
"code": 95172
|
||||
},
|
||||
"Rename '@param' tag name '{0}' to '{1}'": {
|
||||
"category": "Message",
|
||||
"code": 95173
|
||||
},
|
||||
|
||||
"No value exists in scope for the shorthand property '{0}'. Either declare one or provide an initializer.": {
|
||||
"category": "Error",
|
||||
|
||||
Reference in new issue
Block a user