Skip to content

feat: implement multiline formatting options - #298

Draft
DecimalTurn wants to merge 45 commits into
latestfrom
dev-multiline
Draft

feat: implement multiline formatting options#298
DecimalTurn wants to merge 45 commits into
latestfrom
dev-multiline

Conversation

@DecimalTurn

@DecimalTurn DecimalTurn commented Sep 7, 2026

Copy link
Copy Markdown
Owner

Add multilineTable and multilineArray options for controlling generated inline container layout.

Copilot AI lite review requested due to automatic review settings September 7, 2026 02:52

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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 / multilineArray format 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 (ouputoutput) 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 thread src/writer.ts
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
);
Comment thread CHANGELOG.md
[#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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants