Skip to content

Commit

Permalink
Fixed "Delete all unused declarations" to delete self-referential fun…
Browse files Browse the repository at this point in the history
…ctions (#60888)
  • Loading branch information
Andarist authored Jan 18, 2025
1 parent 0745e6a commit 8da951c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/services/codefixes/fixUnusedIdentifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/// <reference path='fourslash.ts' />

//// 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 {};",
});

0 comments on commit 8da951c

Please sign in to comment.