fix: ask KotlinPoet whether a @property name needs backticks - #270
Merged
Marius Volkhart (MariusVolkhart) merged 1 commit intoSep 4, 2026
Merged
Conversation
The KDoc @Property predicate was a hand-written ASCII regex, so it disagreed with the declaration KotlinPoet renders directly below it in both directions: a Unicode-letter name like "café" was backticked in the tag but bare in the declaration, while a Kotlin keyword or all-underscore name was bare in the tag but backticked in the declaration. Reimplementing KotlinPoet's rule is not an option worth taking — it escapes for four independent reasons, and both the rule and the keyword set it consults are internal, so a copy drifts on every KotlinPoet upgrade. Rendering a throwaway PropertySpec asks KotlinPoet directly and stays correct by construction. The check looks for a backtick anywhere in the rendered text rather than for the name appearing backtick-wrapped: KotlinPoet reserves U+00B7 and U+2662 as line-wrapping markers and renders them as spaces, so a name containing one is escaped without appearing verbatim. That requires ruling out a name carrying its own backtick first, which KotlinPoet would read as already escaped. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Marius Volkhart (MariusVolkhart)
requested review from
Matthew Foster (MatthewFoster624) and
Ryan LuMaye (RyanLuMaye)
as code owners
September 4, 2026 13:21
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
Marius Volkhart (MariusVolkhart)
deleted the
fix/kdoc-property-backtick-predicate
branch
September 4, 2026 13:55
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #247.
formatAsKdocPropertyReferencedecided whether a KDoc@propertyname needed backticks withRegex("[A-Za-z_][A-Za-z0-9_]*"), which disagrees with the declaration KotlinPoet renders below it in both directions.caféis a plain Kotlin identifier — bare in the declaration, backticked in the tag, which is what the issue reports. Less obviously,objectand_went the other way: bare in the tag, backticked in the declaration.KotlinPoet escapes a declaration name for four independent reasons — not a legal Java identifier, one of its own reserved
KEYWORDS, contains$, or all underscores — and bothescapeIfNecessaryand the keyword set areinternal. A copy of that list here would drift silently on the next KotlinPoet upgrade, so the predicate now renders a throwawayPropertySpecfor the name and reads back whether KotlinPoet escaped it. The issue's suggestedisJavaIdentifierStart/isJavaIdentifierPartwidening would have fixedcaféand leftobject,_, anda$bstill disagreeing.The check tests for a backtick anywhere in the rendered text rather than for
`name`specifically. KotlinPoet reserves U+00B7 and U+2662 as line-wrapping markers and renders them as spaces, so a name containing one is escaped in the output without appearing there verbatim; matching the name text back read that as "needs no backticks" and emitted a bare, multi-token tag. Names carrying their own backtick are short-circuited before the oracle, since KotlinPoet treats one as already escaped and skips all four checks.Behavior for a name containing
/*or*/(declined outright) and for a name containing a literal backtick is unchanged, as is everything on the SQL-quoting side.Seven tests in
TypeRepositoryTest$PropertyNameKdocDeclarationAgreementassert the@propertytag and thevaldeclaration agree in the same rendered file, forcafé,object,_,a$b,My Col,id, and an interpunct-containing name. No golden file changes; every scenario column name is ASCII.🤖 Generated with Claude Code