Format Document is not idempotent when a line break moves a token that enclosing nodes start at

Abierto
#65,000 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@roninjin10 ya está trabajando en esto.

Desde el 28/10/2026.

  • #64994 de @roninjin10 — abierto

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
25/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Estancado
Stack tecnológico
typescript
Área
devtools, tooling

Línea de trabajo

The report gives two reproductions but names no formatter files or tests. Read the formatting and indentation logic for tokens moved by inserted line breaks, then inspect pull request #64994, which includes a proposed fix and regression tests for both inputs. Done means formatting either example twice produces the same result.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

🔎 Search Terms

format document, formatter, idempotent, idempotence, indentation, continuation indent, non-null assertion

🕗 Version & Regression Information
  • TypeScript 7 at main 4a4b24d5dc96d148641ec6a39c4f5bbf023cbb2f (FormatDocument).
  • TypeScript 6.0.3's language service (getFormattingEditsForDocument) behaves the same way.
⏯ Playground Link

Not applicable: run Format Document twice on the code below (indent size 4, smart indentation).

💻 Code
{{0!
("")}}
{{x
+ y}}
🙁 Actual behavior

The first format indents (""), and + y, by 8 spaces; formatting the result again moves them to 12. With an identifier callee, {{x\n("")}}, the first format already gives 12.

When a formatting rule adds a line break before a token, only the dynamic indenter of the token's own node is updated. In the first input that node is the non-null expression 0!; the call 0!("") and its statement start at the same token and moved too, but keep the indentation they inherited while everything was on one line. In the second input, the binary expression's continuation delta is reset although its statement starts at the same x.

🙂 Expected behavior

The first format gives the stable result, and formatting it again changes nothing.

Additional information about the issue

Found by fuzzing the formatter for idempotence in a fork of this repository. A fix with a regression test for both inputs is in #64994.

This report was drafted with Claude Code (Claude Opus 5.5).

Lenguaje dominante
Go
Estrellas
112k
Forks
15.4k
Merge medio
2 d 21 h
PR fusionados (30 d)
126

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de microsoft/TypeScript

Todos los issues de microsoft/TypeScript

Issues similares

Más issues de Go

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.