From 2f4f3042a8601a0d4c67157a20bc88a0b33345cb Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Mon, 24 Jun 2024 14:18:33 -0400 Subject: [PATCH 1/3] add linter for empty client names --- .../src/decorators.ts | 8 +++++++- .../typespec-client-generator-core/src/lib.ts | 6 ++++++ .../test/decorators.test.ts | 16 ++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/packages/typespec-client-generator-core/src/decorators.ts b/packages/typespec-client-generator-core/src/decorators.ts index d3786b8a0d..3ceff1c721 100644 --- a/packages/typespec-client-generator-core/src/decorators.ts +++ b/packages/typespec-client-generator-core/src/decorators.ts @@ -977,7 +977,13 @@ export function $clientName( } } } - + if (value.trim() === "") { + reportDiagnostic(context.program, { + code: "empty-client-name", + format: {}, + target: entity, + }); + } setScopedDecoratorData(context, $clientName, clientNameKey, entity, value, scope); } diff --git a/packages/typespec-client-generator-core/src/lib.ts b/packages/typespec-client-generator-core/src/lib.ts index 4976ee4f3b..a40202e151 100644 --- a/packages/typespec-client-generator-core/src/lib.ts +++ b/packages/typespec-client-generator-core/src/lib.ts @@ -147,6 +147,12 @@ export const $lib = createTypeSpecLibrary({ default: paramMessage`Can not find name for your emitter, please check your emitter name.`, }, }, + "empty-client-name": { + severity: "warning", + messages: { + default: `You cannot pass an empty value to the @clientName decorator`, + }, + }, }, }); diff --git a/packages/typespec-client-generator-core/test/decorators.test.ts b/packages/typespec-client-generator-core/test/decorators.test.ts index a0e2bbfa18..2e86e17e00 100644 --- a/packages/typespec-client-generator-core/test/decorators.test.ts +++ b/packages/typespec-client-generator-core/test/decorators.test.ts @@ -2684,6 +2684,22 @@ describe("typespec-client-generator-core: decorators", () => { "body" ); }); + it("empty client name", async () => { + const diagnostics = await runner.diagnose(` + @service({}) + namespace MyService; + + @clientName(" ") + model Test { + id: string; + prop: string; + } + `); + + expectDiagnostics(diagnostics, { + code: "@azure-tools/typespec-client-generator-core/empty-client-name", + }); + }); }); describe("versioning projection", () => { From 5e1e138459f5c76554fc5ae69e5de1c534f0a829 Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Mon, 24 Jun 2024 14:18:49 -0400 Subject: [PATCH 2/3] add changeset --- .../changes/whitespace_client_name-2024-5-24-14-18-45.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .chronus/changes/whitespace_client_name-2024-5-24-14-18-45.md diff --git a/.chronus/changes/whitespace_client_name-2024-5-24-14-18-45.md b/.chronus/changes/whitespace_client_name-2024-5-24-14-18-45.md new file mode 100644 index 0000000000..5746fc36b6 --- /dev/null +++ b/.chronus/changes/whitespace_client_name-2024-5-24-14-18-45.md @@ -0,0 +1,7 @@ +--- +changeKind: fix +packages: + - "@azure-tools/typespec-client-generator-core" +--- + +Add linter for empty `@clientName` values \ No newline at end of file From 1216a5655bff942fd80097a99ced0bff4f0e7c29 Mon Sep 17 00:00:00 2001 From: iscai-msft <43154838+iscai-msft@users.noreply.github.com> Date: Mon, 24 Jun 2024 14:26:29 -0400 Subject: [PATCH 3/3] Update packages/typespec-client-generator-core/src/lib.ts Co-authored-by: catalinaperalta --- packages/typespec-client-generator-core/src/lib.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/typespec-client-generator-core/src/lib.ts b/packages/typespec-client-generator-core/src/lib.ts index a40202e151..fbca5ba653 100644 --- a/packages/typespec-client-generator-core/src/lib.ts +++ b/packages/typespec-client-generator-core/src/lib.ts @@ -150,7 +150,7 @@ export const $lib = createTypeSpecLibrary({ "empty-client-name": { severity: "warning", messages: { - default: `You cannot pass an empty value to the @clientName decorator`, + default: `Cannot pass an empty value to the @clientName decorator`, }, }, },