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

Ouverte
#65,000 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

@roninjin10 y travaille déjà.

Depuis le 28/10/2026.

  • #64994 par @roninjin10 — ouverte

Évaluation

Difficulté
4/5
Temps estimé
3-5 jours
Accessibilité débutants
25/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
À l'abandon
Stack technique
typescript
Domaine
devtools, tooling

Piste de recherche

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.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

🔎 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).

Langage dominant
Go
Étoiles
112k
Forks
15.4k
Merge moyen
3 j 6 h
PR mergées (30 j)
136

Préparer son environnement

Ouvrir dans Codespaces

Lance le conteneur de développement du projet dans votre navigateur, avec votre propre compte GitHub.

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de microsoft/TypeScript

Toutes les issues de microsoft/TypeScript

Issues similaires

Plus d'issues Go

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.