Hacktoberfest 2026: as issues que os mantenedores marcaram para outubro, abertas e boas para iniciantes. Ver issues do Hacktoberfest

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

Fechada
#9,060 0 comentários 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 1 dia

@cknitt já está trabalhando nisso.

Desde 27/10/2026.

  • #9061 de @cknitt — aberto

Avaliação

Dificuldade
4/5
Tempo estimado
3-5 dias
Facilidade para iniciantes
35/100
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Estagnada
Stack de tecnologia
ocaml
Domínio
tooling

Direção de pesquisa

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.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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.

Linguagem predominante
OCaml
Estrelas
7.5k
Forks
483
Merge médio
20h 50min
PRs com merge (30d)
230

Preparar o ambiente

Abrir no Codespaces

Inicia o contêiner de desenvolvimento do projeto no navegador, com a sua própria conta do GitHub.

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de rescript-lang/rescript

Todas as issues de rescript-lang/rescript

Issues semelhantes

Mais issues de DevTools

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.