Skip to content

Commit 011b567

Browse files
committed
Don't offer to prepend an underscore to the name of an unused private property
1 parent 3a05363 commit 011b567

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/services/codefixes/fixUnusedIdentifier.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace ts.codefix {
1818

1919
switch (token.kind) {
2020
case ts.SyntaxKind.Identifier:
21-
return deleteIdentifierOrPrefixWithUnderscore(<Identifier>token);
21+
return deleteIdentifierOrPrefixWithUnderscore(<Identifier>token, context.errorCode);
2222

2323
case SyntaxKind.PropertyDeclaration:
2424
case SyntaxKind.NamespaceImport:
@@ -54,7 +54,7 @@ namespace ts.codefix {
5454
};
5555
}
5656

57-
function deleteIdentifierOrPrefixWithUnderscore(identifier: Identifier): CodeAction[] | undefined {
57+
function deleteIdentifierOrPrefixWithUnderscore(identifier: Identifier, errorCode: number): CodeAction[] | undefined {
5858
const parent = identifier.parent;
5959
switch (parent.kind) {
6060
case ts.SyntaxKind.VariableDeclaration:
@@ -76,8 +76,10 @@ namespace ts.codefix {
7676

7777
case ts.SyntaxKind.Parameter:
7878
const functionDeclaration = <FunctionDeclaration>parent.parent;
79-
return [functionDeclaration.parameters.length === 1 ? deleteNode(parent) : deleteNodeInList(parent),
80-
prefixIdentifierWithUnderscore(identifier)];
79+
const deleteAction = functionDeclaration.parameters.length === 1 ? deleteNode(parent) : deleteNodeInList(parent);
80+
return errorCode === Diagnostics.Property_0_is_declared_but_its_value_is_never_read.code
81+
? [deleteAction]
82+
: [deleteAction, prefixIdentifierWithUnderscore(identifier)];
8183

8284
// handle case where 'import a = A;'
8385
case SyntaxKind.ImportEqualsDeclaration:

0 commit comments

Comments
 (0)