From c06849ad16a1ab9bb1e457755f3ef22cf231cac5 Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Tue, 8 Feb 2022 23:39:54 +0200 Subject: [PATCH] fix(47787): show QF to delete parameter in getter (#47797) --- src/services/codefixes/fixUnusedIdentifier.ts | 4 ++++ src/services/formatting/smartIndenter.ts | 2 ++ ...ixUnusedIdentifier_parameterInGetAccessor.ts | 17 +++++++++++++++++ 3 files changed, 23 insertions(+) create mode 100644 tests/cases/fourslash/codeFixUnusedIdentifier_parameterInGetAccessor.ts diff --git a/src/services/codefixes/fixUnusedIdentifier.ts b/src/services/codefixes/fixUnusedIdentifier.ts index f11c6bce72f..df44b8b2e5a 100644 --- a/src/services/codefixes/fixUnusedIdentifier.ts +++ b/src/services/codefixes/fixUnusedIdentifier.ts @@ -316,6 +316,10 @@ namespace ts.codefix { // Setter must have a parameter return false; + case SyntaxKind.GetAccessor: + // Getter cannot have parameters + return true; + default: return Debug.failBadSyntaxKind(parent); } diff --git a/src/services/formatting/smartIndenter.ts b/src/services/formatting/smartIndenter.ts index de223963832..da74c36afcb 100644 --- a/src/services/formatting/smartIndenter.ts +++ b/src/services/formatting/smartIndenter.ts @@ -432,6 +432,8 @@ namespace ts.formatting { case SyntaxKind.ConstructorType: case SyntaxKind.ConstructSignature: return getList((node as SignatureDeclaration).typeParameters) || getList((node as SignatureDeclaration).parameters); + case SyntaxKind.GetAccessor: + return getList((node as GetAccessorDeclaration).parameters); case SyntaxKind.ClassDeclaration: case SyntaxKind.ClassExpression: case SyntaxKind.InterfaceDeclaration: diff --git a/tests/cases/fourslash/codeFixUnusedIdentifier_parameterInGetAccessor.ts b/tests/cases/fourslash/codeFixUnusedIdentifier_parameterInGetAccessor.ts new file mode 100644 index 00000000000..e70afb997db --- /dev/null +++ b/tests/cases/fourslash/codeFixUnusedIdentifier_parameterInGetAccessor.ts @@ -0,0 +1,17 @@ +/// + +// @noUnusedLocals: true +// @noUnusedParameters: true + +////let foo = { +//// get x(/**/param) {} +////} + +verify.codeFix({ + description: "Remove unused declaration for: 'param'", + index: 0, + newFileContent: +`let foo = { + get x() {} +}` +})