Skip to content

Feature: Added --check option to cadl format - #47

Merged
Timothee Guerin (timotheeguerin) merged 3 commits into
microsoft:mainfrom
timotheeguerin:feature/format-check
Nov 8, 2021
Merged

Timothee Guerin (timotheeguerin) merged 3 commits into
microsoft:mainfrom
timotheeguerin:feature/format-check

Conversation

@timotheeguerin

@timotheeguerin Timothee Guerin (timotheeguerin) commented Nov 8, 2021 •

Copy link
Copy Markdown
Member

Added --check option similar to rust fmt --check to add some option for user to validate files are formatted without having to use prettier directly.

Realized we were missing this and to ensure cadl user can make sure they code is formatted, I believe this is required.

Example running cadl format **/*.cadl --check in this repo:
image

@timotheeguerin
Timothee Guerin (timotheeguerin) merged commit 4c82558 into microsoft:main Nov 8, 2021
@timotheeguerin
Timothee Guerin (timotheeguerin) deleted the feature/format-check branch November 8, 2021 18:00
om singhal (Om-singhaI) pushed a commit to Om-singhaI/typespec that referenced this pull request Aug 27, 2026
…osoft#11766)

## Summary
Fixes generated Java code corruption when a Javadoc table cell
(parameter name/type/description, or response header
name/type/description) contains a literal `*/` sequence.

## Root cause
Values written into the optional-parameters and response-headers Javadoc
tables are escaped for XML special characters via
`CodeNamer.escapeXmlComment`, but never comment-escaped. When a value
embeds `*/` (for example, TCGC's Content-Type parameter doc for an
unconstrained `Http.File` content type, whose `contentTypes` array is
`["*/*"]`), the literal `*/` prematurely closes the surrounding
generated `/** ... */` Javadoc block. This corrupts the rest of the
generated Java file and breaks compilation with a long cascade of parser
errors.

## Fix
`CodeNamer.escapeComment` already exists and correctly escapes `*/` to
`*&microsoft#47;`, but it wasn't applied consistently. This change centralizes
the escaping in the shared `ClientMethodTemplateBase#javadocTable`
helper so every cell value (not just parameter descriptions) is
protected, alongside the existing XML escaping.

## Context
Found while fixing Azure/typespec-azure#5288
(Azure/typespec-azure#5306), where making the Content-Type parameter for
default `Http.File` bodies client-visible (previously hidden as a
constant) surfaced this latent Javadoc-escaping bug in CI.

---------

Co-authored-by: iscai-msft <isabellavcai@gmail.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 6a785543-019d-4b0c-9750-5affcfc900ee
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants