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

オープン
#65,000 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@roninjin10 がすでに取り組んでいます。

2026年10月28日 から。

  • #64994 @roninjin10 による — オープン

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
25/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
停滞
技術スタック
typescript
領域
devtools, tooling

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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

主要言語
Go
スター
112k
フォーク
16k
平均マージ
3日 4時間
マージ済み PR(30日)
145

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

microsoft/TypeScript のほかの issue

microsoft/TypeScript の issue をすべて見る

似ている issue

Go の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。