prefix-unused-parameter-with-_ codefix now works in jsdoc @param (#36152)

* Fix prepending unused TypeScript variables with underscore doesn't rename JSDoc @param.
Fix test for quick fix "Prefix all unused declarations with '_' where possible".
Fixes #33021.

* Replace FindAllReferences.Core.eachSymbolReferenceInFile function call to more ligher call of getJSDocParameterTags when searching for a parameter in jsdoc.

* Remove redundant constant declaration.

* Add test for prefix single unused parameter in jsdoc.
This commit is contained in:
sergeir82 2020-04-17 23:18:05 +03:00 committed by GitHub
parent deb5bac520
commit b346f5764e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 1 deletions

View File

@ -154,6 +154,13 @@ namespace ts.codefix {
}
if (isIdentifier(token) && canPrefix(token)) {
changes.replaceNode(sourceFile, token, createIdentifier(`_${token.text}`));
if (isParameter(token.parent)) {
getJSDocParameterTags(token.parent).forEach((tag) => {
if (isIdentifier(tag.name)) {
changes.replaceNode(sourceFile, tag.name, createIdentifier(`_${tag.name.text}`));
}
});
}
}
}

View File

@ -3,6 +3,10 @@
// @noUnusedLocals: true
// @noUnusedParameters: true
/////**
//// * @param a First parameter.
//// * @param b Second parameter.
//// */
////function f(a, b) {
//// const x = 0; // Can't be prefixed, ignored
////}
@ -12,7 +16,11 @@ verify.codeFixAll({
fixId: "unusedIdentifier_prefix",
fixAllDescription: "Prefix all unused declarations with '_' where possible",
newFileContent:
`function f(_a, _b) {
`/**
* @param _a First parameter.
* @param _b Second parameter.
*/
function f(_a, _b) {
const x = 0; // Can't be prefixed, ignored
}
type Length<T> = T extends ArrayLike<infer _U> ? number : never;`,

View File

@ -0,0 +1,25 @@
/// <reference path='fourslash.ts' />
// @noUnusedLocals: true
// @noUnusedParameters: true
/////**
//// * @param a
//// * @param b
//// */
////function f(a, b) {
//// const x = a;
////}
verify.codeFix({
description: "Prefix 'b' with an underscore",
index: 1,
newFileContent:
`/**
* @param a
* @param _b
*/
function f(a, _b) {
const x = a;
}`,
});