Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

Formatter moves a line comment in a switch/if/loop operand into the block

未關閉
#9,060 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

@cknitt 已經在處理了。

開始於 2026年10月27日。

  • #9061 來自 @cknitt —— 未關閉

評估

難度
4/5
預估耗時
3-5 天
新手友好度
35/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
停滯
技術堆疊
ocaml
領域
tooling

研究方向

The issue describes the formatter’s line suffix handling and gives operand examples, but names no source files or tests. Start by locating the printer logic that queues trailing line comments and the formatter tests for switch, if, loop, and try operands. Add cases that verify comments stay in the operand across repeated formatting; done means formatting is idempotent for the examples. Pull request #9061 is already open.

由索引模型根據 Issue 內容生成。

描述

A line comment inside the operand of switch, if, while, for, for..of, for await..of or try moves when formatting: first after the {, then on the next run into the block. Formatting is not idempotent.

switch obj // c
.x {
| _ => ()
}

First run:

switch obj.x { // c
| _ => ()
}

Second run, the comment is now in the block:

switch obj.x {
// c
| _ => ()
}

The same happens with if, while, for..of, for await..of, try (where the comment moves past catch) and with these operands:

  • obj // c\n.x.y and obj // c\n.x // d\n.y
  • arr[// c\n0], obj[// c\n"member"], obj["member"] // c\n{
  • obj // c\n->f
  • a // c\n+ b
  • for i in 0 // c\nto n {: the comment moves past to n and into the loop body

switch f(// c\nx) { is fine, because the arguments group breaks after the comment.

Expected: the comment stays in the operand, for example

switch (
  obj.x // c
) {
| _ => ()
}

Cause: the printer queues a trailing line comment as a line suffix and prints it at the next line break of a breaking group. The field access, object get, pipe or binary expression is printed flat with no line break after the comment, so the first break is the one after the block's {.

Found while reviewing #8906, which is about a related case, but this bug is already on master.

主要語言
OCaml
星號
7.5k
分支
483
平均合併
20 小時 7 分鐘
30 天內合併 PR
227

環境準備

在 Codespaces 中開啟

在瀏覽器裡用你自己的 GitHub 帳號啟動這個專案的開發容器。

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

rescript-lang/rescript 的其他 Issue

查看 rescript-lang/rescript 的全部 Issue

相似的 Issue

更多 DevTools Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。