mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-06 01:39:28 -06:00
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:
parent
deb5bac520
commit
b346f5764e
@ -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}`));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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;`,
|
||||
|
||||
25
tests/cases/fourslash/codeFixUnusedIdentifier_prefix.ts
Normal file
25
tests/cases/fourslash/codeFixUnusedIdentifier_prefix.ts
Normal 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;
|
||||
}`,
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user