Format Document is not idempotent when a line break moves a token that enclosing nodes start at
維護者通常 1 天內回覆
評估
- 難度
- 4/5
- 預估耗時
- 3-5 天
- 新手友好度
- 25/100
- Issue 類型
- 缺陷
- 描述清晰度
- 描述清楚
- 活躍度
- 停滯
- 技術堆疊
- typescript
研究方向
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
main4a4b24d5dc96d148641ec6a39c4f5bbf023cbb2f (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
- 分支
- 15.4k
- 平均合併
- 2 天 21 小時
- 30 天內合併 PR
- 126
環境準備
在瀏覽器裡用你自己的 GitHub 帳號啟動這個專案的開發容器。
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
microsoft/TypeScript 的其他 Issue
-
Won't Fix
難度 2/5 1-3 小時 新手友好度 62/100
microsoft/TypeScript#65107 · 1 則留言 ·
維護者通常 1 天內回覆
-
Native API: formatDiagnosticsWithColorAndContext drops related information without a file location可能已有人在做 @timurzvural 今天認領。 未關閉
難度 2/5 1-3 小時 新手友好度 75/100
microsoft/TypeScript#65087 ·
維護者通常 1 天內回覆
-
TS7 LSP: documentHighlight returns nothing when the file path contains '@'可能重新可做 關聯的 PR 已關閉且未合併。 未關閉Bug
難度 2/5 1-3 小時 新手友好度 78/100
microsoft/TypeScript#64758 ·
維護者通常 1 天內回覆
-
Language server (tsc --lsp) exits with code 1 after `shutdown` and `exit`可能已有人在做 @rajnish-verma-22172 於 12 天前認領。 未關閉Bug
難度 2/5 1-3 小時 新手友好度 76/100
microsoft/TypeScript#64742 · 1 則留言 ·
維護者通常 1 天內回覆
-
Class names `eval` and `arguments` are not reported as invalid strict mode bindings可能已有人在做 @dmety 於 26 天前認領。 未關閉Bug
難度 2/5 1-3 小時 新手友好度 68/100
microsoft/TypeScript#64661 ·
維護者通常 1 天內回覆
查看 microsoft/TypeScript 的全部 Issue
相似的 Issue
-
fix(scan): validate and normalize output format in validate-contract可能已有人在做 @WKr1shna 今天認領。 未關閉
難度 2/5 1-3 小時 新手友好度 78/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 72/100
維護者通常 1 天內回覆
-
bug good first issue help wanted
難度 2/5 1-3 小時 新手友好度 70/100
-
難度 1/5 1 小時以內 新手友好度 78/100
argoproj/argo-workflows#17397 ·
維護者通常 1 天內回覆
-
[mesheryctl] design delete fails when passing file or URL as positional argument可能已有人在做 關聯的 PR 仍在進行中或已合併。 未關閉component/mesheryctl kind/bug language/go
難度 2/5 1-3 小時 新手友好度 74/100
meshery/meshery#22772 · 3 則留言 ·
維護者通常 1 天內回覆