Report linter diagnostics on library template members the user gave a type to - #11862
Conversation
commit: |
|
All changed packages have been documented.
Show changes
|
|
You can try these changes here
|
Narrow the fix so a library-declared member is reported only when its declared type depends on a template parameter the user passed an argument for, and retarget the diagnostic to that argument node in the user's project.
A member the parameter merely appears inside, such as `value: T[]` in `Page<T>`, is the library's own declaration: a diagnostic about it is the library's to fix no matter which item type the user passed. Reported against azure-rest-api-specs this removes the `missing-x-ms-identifiers` findings on `Page<X>` while keeping `no-unknown` on `ArmResponse<unknown>` and `missing-x-ms-identifiers` where the user passed the array itself.
A linter rule can never report on a type that exists only because the user instantiated a library template.
reportDiagnostickeeps a diagnostic only when its target resolves to the project, and an instantiated member's source location is the template declaration inside the library, so the diagnostic is dropped without a trace.That hides real problems. Given ARM's
a rule that objects to
Typebeing auuidcannot say so abouteven though the
uuidis the user's own choice, written in their own file. This was found on Azure/typespec-azure#5336, where it silenced 9 declarations across 6 projects. A plain (non-linter) diagnostic on the exact same target renders fine, complete with an instantiation trace, so the two kinds of diagnostic disagree about the same code.Now a library-declared member is reported when both of the following hold, and the diagnostic is moved onto the argument in the user's own file:
name: Typequalifies, so the type really is the one they passed.value: T[]inPage<T>does not: the array is the library's own declaration, and a complaint about it is the library's to fix whichever item type is passed.unknown. When they pass one of their own declarations, anything wrong with it is reportable on that declaration, where they can see it in context, so the instantiation adds nothing.Together these keep the diagnostic pointed at a line the reader can act on. Measured against
azure-rest-api-specs, this reports the cases the rules were written to catch —ArmResponse<unknown>,ArmResponse<NetworkTrace[]>— without reporting members whose problem lies in a model the author already owns.#suppressnow walks the template instantiation trace too, so the diagnostic can be suppressed where the user instantiates the template, which is the only place they can write a directive.Fixes #11861
Known follow-up
documentation-requiredreports on a type whose documentation was blanked with@@doc(X, ""), and points at the type rather than at the augmentation that blanked it. The rule knows it is about@docand can point at the responsible node; the linter cannot guess which decorator a rule cares about. Tracked in Azure/typespec-azure#5445.