Don't offer to prepend an underscore to the name of an unused private property

This commit is contained in:
Andrew Casey 2017-11-29 18:05:36 -08:00
parent 3a05363a29
commit 011b567918

View file

@ -18,7 +18,7 @@ namespace ts.codefix {
switch (token.kind) {
case ts.SyntaxKind.Identifier:
return deleteIdentifierOrPrefixWithUnderscore(<Identifier>token);
return deleteIdentifierOrPrefixWithUnderscore(<Identifier>token, context.errorCode);
case SyntaxKind.PropertyDeclaration:
case SyntaxKind.NamespaceImport:
@ -54,7 +54,7 @@ namespace ts.codefix {
};
}
function deleteIdentifierOrPrefixWithUnderscore(identifier: Identifier): CodeAction[] | undefined {
function deleteIdentifierOrPrefixWithUnderscore(identifier: Identifier, errorCode: number): CodeAction[] | undefined {
const parent = identifier.parent;
switch (parent.kind) {
case ts.SyntaxKind.VariableDeclaration:
@ -76,8 +76,10 @@ namespace ts.codefix {
case ts.SyntaxKind.Parameter:
const functionDeclaration = <FunctionDeclaration>parent.parent;
return [functionDeclaration.parameters.length === 1 ? deleteNode(parent) : deleteNodeInList(parent),
prefixIdentifierWithUnderscore(identifier)];
const deleteAction = functionDeclaration.parameters.length === 1 ? deleteNode(parent) : deleteNodeInList(parent);
return errorCode === Diagnostics.Property_0_is_declared_but_its_value_is_never_read.code
? [deleteAction]
: [deleteAction, prefixIdentifierWithUnderscore(identifier)];
// handle case where 'import a = A;'
case SyntaxKind.ImportEqualsDeclaration: