Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

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

Đã đóng
#9,060 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@cknitt đang làm issue này rồi.

Từ ngày 27/10/2026.

  • #9061 của @cknitt — đang mở

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
ocaml
Lĩnh vực
tooling

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
OCaml
Star
7.5k
Fork
483
Merge trung bình
20 giờ 50 phút
Pull request đã merge (30 ngày)
230

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của rescript-lang/rescript

Tất cả issue của rescript-lang/rescript

Issue tương tự

Thêm issue về DevTools

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.