You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 4b1fcda
Browse filesBrowse the repository at this point in the historyBrowse files
Keep doc comments and comments in place in four formatter cases (#9119)
Why:
The formatter put doc comments and comments in the wrong place in four
of the cases reported in #9107, and in one of them it reordered the
attributes in the AST. Doc comments after an attribute were moved in
front of all attributes. A single parameter with a doc comment was
hugged, so its pattern started at column 0. A comment before a list's
tail spread was printed after the dots, in expressions and in
patterns. A file with only a line comment got an extra newline.
Only the doc comments in front of every other attribute are now
printed first; later ones stay in their place, inline. The fifth case,
a comment after a parenthesized `switch` or `if` operand that moves
into the block, keeps its stable output.
AST modified (doc comment after an attribute, after formatting):
Example:
type u = /** d1 */ @A /** d2 */ {x: int}
Before (parse):
type_declaration "u"
attribute "res.doc"
attribute "res.doc"
attribute "a"
After (parse):
type_declaration "u"
attribute "res.doc"
attribute "a"
attribute "res.doc"
Format modified (doc comment after an attribute):
Example:
type u = /** d1 */ @A /** d2 */ {x: int}
Before (rescript):
/** d1 */
/** d2 */
@A type u = {x: int}
After (rescript):
/** d1 */
@A /** d2 */ type u = {x: int}
Format modified (doc comment on a hugged parameter):
Example:
let f = (/** r */ {x, y}) => x
Before (rescript):
let f = (/** r */
{x, y}) => x
After (rescript):
let f = (
/** r */
{x, y},
) => x
Format modified (comment before a list's tail spread):
Example:
let l = list{1, /* c */ ...xs}
let f = (list{a, /* c */ ...rest}) => a
Before (rescript):
let l = list{1, .../* c */ xs}
let f = (list{a, .../* c */ rest}) => a
After (rescript):
let l = list{1, /* c */ ...xs}
let f = (list{a, /* c */ ...rest}) => a
Format modified (file with only a line comment):
Example:
// c
Before (text): "// c\n\n"
After (text): "// c\n"
Review: Why not fix the comment after a parenthesized operand? It formats
stably with the same AST; fixing it needs a token flag on comments or
operand locations that include the parentheses.
Fixes: #9107
Claude-Session: https://claude.ai/code/session_01Kbf3gGkPma9LAZimuQjnrP
Signed-off-by: Christoph Knittel <ck@cca.io>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
- Fix the formatter's placement of a doc comment on a single hugged parameter, of doc comments after an attribute, and of a comment before a list's tail spread, and the extra newline after a file with only a line comment.
0 commit comments