Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tcgc] add linter for empty client names #1066

Merged
merged 3 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: fix
packages:
- "@azure-tools/typespec-client-generator-core"
---

Add linter for empty `@clientName` values
8 changes: 7 additions & 1 deletion packages/typespec-client-generator-core/src/decorators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
6 changes: 6 additions & 0 deletions packages/typespec-client-generator-core/src/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
iscai-msft marked this conversation as resolved.
Show resolved Hide resolved
},
},
},
});

Expand Down
16 changes: 16 additions & 0 deletions packages/typespec-client-generator-core/test/decorators.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down
Loading