feat: implement multiline formatting options - #298
Draft
DecimalTurn wants to merge 45 commits into
Draft
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
perLine() can mis-detect “one item per structural line” for containers containing multiline items, which can lead to incorrect layout decisions.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Implements configurable multiline layout for newly generated inline arrays and inline tables, threading the new formatting controls through parsing, patching, writer positioning, and TOML emission, with expanded regression + fuzz coverage and updated docs/tooling.
Changes:
- Add
multilineTable/multilineArrayformat options (including validation, defaults, docs, and public typing). - Teach
stringify()/patch()generation and patch replacement paths to preserve/resolve multiline intent and normalize generated inline container row positioning. - Add new regression tests, fuzz harness variant (
fuzz3), and helper scripts for debugging/distilling failures.
File summaries
| File | Description |
|---|---|
| src/writer.ts | Extends shifting/inline insertion logic and adds inline-container layout-aware per-line detection. |
| src/toml-format.ts | Adds multiline container options, defaults, type, validation, and resolution wiring. |
| src/toml-document.ts | Threads explicitness flags into patchCst to preserve caller intent for generated formatting. |
| src/to-toml.ts | Adjusts delimiter emission and cursor gap handling for generated multiline container positioning. |
| src/patch.ts | Adds multiline-aware regeneration/normalization paths and threads formatting explicitness into patching. |
| src/parse-js.ts | Adds depth/parent layout context to generation and marks generated containers with layout decisions. |
| src/inline-layout.ts | Marks positioned inline containers and positions generated nested multiline inline tables inside arrays. |
| src/inline-format.ts | New internal module for storing inline-container layout decisions and generated-layout metadata. |
| src/index.ts | Exports MultilineContainerMode type alongside TomlFormat. |
| src/generate.ts | Adds a shift option to support generated multiline end-column behavior when producing key-values. |
| src/formatter.ts | Normalizes generated inline rows and container rows for multiline layout and bracket spacing. |
| src/tests/toml-format.test.ts | Adds tests for multiline mode defaults, validation, and constructor argument compatibility. |
| src/tests/stringify.test.ts | Fixes variable typo (ouput → output) in stringify tests. |
| src/tests/patch.test.ts | Adds distilled regression coverage for multiline layout and indentation interactions. |
| src/tests/patch.indentation.test.ts | Updates indentation tests to pass multiline options and removes expected-failure markers. |
| src/tests/patch.fuzz.test.ts | Extends fuzz regression coverage and adds distilled regressions for new fuzz variant seeds. |
| src/tests/multiline-formatting.test.ts | New exact-output tests for multiline container formatting modes and interactions. |
| src/tests/fuzz-patch3.ts | New fuzz harness variant enabling randomized indentation + multiline modes. |
| src/tests/fuzz-patch2.ts | Updates fuzz2 harness to pass through multiline randomization flags. |
| src/tests/fuzz-patch.ts | Adds multiline randomization to format generation and fuzz harness plumbing. |
| scripts/test-debug.mjs | New helper to capture unit test output to a Markdown file for debugging. |
| scripts/generate-seed-toml.ts | New helper to write deterministic seed TOML to disk for inspection. |
| scripts/fuzz-run3.ts | New runner for fuzz3 harness (compact dotted-key syntax + randomized multiline formats). |
| scripts/distill-seed.ts | Extends distillation to support fuzz variants and improved failure classification. |
| scripts/distill-and-append-seed.ts | New helper to distill and append regression tests directly into the fuzz test file. |
| README.md | Documents the new multiline format options and adds a clearer configuration example. |
| package.json | Adds test:output, seed-toml, and fuzz3 scripts. |
| docs/PLAN-Multiline-Formatting.md | New design/implementation plan documenting the multiline feature behavior and scope. |
| docs/Fuzz-Testing.md | Documents seed TOML generation and related fuzz workflows. |
| docs/Formatting.md | Adds/updates documentation for indentWidth, useTabsForIndentation, and multiline modes. |
| CONTRIBUTING.md | Adds guidance for captured test output and fuzz3 reproduction/distillation workflows. |
| CHANGELOG.md | Adds entries for indentWidth and multiline formatting options. |
| .vscode/tasks.json | Adds a VS Code task to run tests with captured output. |
| .vscode/launch.json | Updates debug launch configs from Jest to Vitest. |
Review details
- Files reviewed: 34/34 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+1391
to
+1395
| const items = excluded ? array.items.filter(item => item !== excluded) : array.items; | ||
| if (!items.length) return array.loc.end.line > array.loc.start.line; | ||
| const startsOnSeparateLines = array.loc.end.line > array.loc.start.line && items.every((item, index) => | ||
| index === 0 || item.loc.start.line > items[index - 1].loc.start.line | ||
| ); |
| [#288]: https://github.com/DecimalTurn/toml-patch/pull/288 | ||
| [#289]: https://github.com/DecimalTurn/toml-patch/pull/289 | ||
| [#290]: https://github.com/DecimalTurn/toml-patch/pull/290 | ||
| [#291] https://github.com/DecimalTurn/toml-patch/pull/291 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add
multilineTableandmultilineArrayoptions for controlling generated inline container layout.