Add AZC0034 C# type-name conflict linter - #4910
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 697b40ed-4fb1-4300-991d-f58a799b2765
|
All changed packages have been documented.
Show changes
|
commit: |
|
You can try these changes here
|
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 697b40ed-4fb1-4300-991d-f58a799b2765
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 12e46e52-385e-444f-a3fc-ee8cd7d97c83
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 12e46e52-385e-444f-a3fc-ee8cd7d97c83
| @@ -0,0 +1,11340 @@ | |||
| // Copyright (c) Microsoft Corporation. All rights reserved. | |||
There was a problem hiding this comment.
that is quite a large file, do we really need every single instance here, are those not namespace that we should ban instead?
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| // <auto-generated> |
There was a problem hiding this comment.
This is a c# doc comment format, align to JS Doc
There was a problem hiding this comment.
when is this going to be run?
| "format:dir": "prettier --write", | ||
| "format:extra": "pnpm run-all format:extra", | ||
| "format:extra:check": "pnpm run-all format:extra:check", | ||
| "generate:azc0034-catalog": "tsx eng/scripts/generate-azc0034-catalog.ts", |
There was a problem hiding this comment.
the c# code for is is quite meaningless do not include it in this repo apart from the doc
Summary
csharp-no-type-name-conflictlinter rule for AZC0034-style reserved C# type-name conflicts@@clientNamequick fixes, tests, docs, ruleset registration, and Chronus change entryCatalog generation
The checked-in catalog is generated by
eng/scripts/generate-azc0034-catalog.tsand consumed at lint time frompackages/typespec-client-generator-core/src/rules/azc0034-reserved-type-names.generated.ts.The generator fetches the same two source files used by the .NET Azure SDK analyzer from
Azure/azure-sdk-for-net:sdk/tools/Azure.SdkAnalyzers/src/reserved-type-names.txtsdk/tools/Azure.SdkAnalyzers/src/reserved-type-qualified-names.txtDuring generation, the script validates that both files have matching line counts, no blank names, sorted and unique simple names, and matching simple-name/qualified-name pairs. It emits a TypeScript map keyed by the reserved C# metadata name, with the conflicting fully qualified type name and package name as diagnostic details. The generated file includes source file paths and SHA256 hashes so future catalog refreshes are traceable.
Suggested fix generation
When a model, enum, or union has a generated C# name that appears in the catalog, the rule suggests adding a C#
@@clientNameoverride inclient.tsp.The suggested name is built from a contextual prefix plus the conflicting C# name. The prefix comes from the enclosing
@servicenamespace when available; otherwise it falls back to the nearest user namespace. The rule uses the C# library name for that namespace, strips a trailingClientsuffix when present, and normalizes it to PascalCase. For example,namespace Billing; model Operation {}suggestsBillingOperation.If the first candidate is also reserved, the rule tries stable fallback suffixes in order: no suffix,
Info,Data, thenType. This keeps the quick fix deterministic while avoiding suggestions that would still trigger AZC0034.Companion spec PRs