diff --git a/src/services/codefixes/fixUnusedIdentifier.ts b/src/services/codefixes/fixUnusedIdentifier.ts index 1974e8067a45f..9d6c3be78c1cb 100644 --- a/src/services/codefixes/fixUnusedIdentifier.ts +++ b/src/services/codefixes/fixUnusedIdentifier.ts @@ -200,6 +200,9 @@ registerCodeFix({ else if (canDeleteEntireVariableStatement(sourceFile, token)) { deleteEntireVariableStatement(changes, sourceFile, token.parent as VariableDeclarationList); } + else if (isIdentifier(token) && isFunctionDeclaration(token.parent)) { + deleteFunctionLikeDeclaration(changes, sourceFile, token.parent as FunctionLikeDeclaration); + } else { tryDeleteDeclaration(sourceFile, token, changes, checker, sourceFiles, program, cancellationToken, /*isFixAll*/ true); } diff --git a/tests/cases/fourslash/codeFixUnusedIdentifier_all_selfReferencingFunction.ts b/tests/cases/fourslash/codeFixUnusedIdentifier_all_selfReferencingFunction.ts new file mode 100644 index 0000000000000..8017973ee96da --- /dev/null +++ b/tests/cases/fourslash/codeFixUnusedIdentifier_all_selfReferencingFunction.ts @@ -0,0 +1,18 @@ +/// + +//// function fibonacci(n: number): number { +//// if (n <= 1) { +//// return n; +//// } +//// return fibonacci(n - 1) + fibonacci(n - 2); +//// } +//// +//// function other() {} +//// +//// export {}; + +verify.codeFixAll({ + fixId: "unusedIdentifier_delete", + fixAllDescription: ts.Diagnostics.Delete_all_unused_declarations.message, + newFileContent: "\n\nexport {};", +});