Skip to content

fix(tomlfmt): keep arrays inside inline tables on a single line - #642

Open
MsfPablo wants to merge 3 commits into
Boeing:feat/3.0from
MsfPablo:fix/tomlfmt-inline-table-array-single-line
Open

fix(tomlfmt): keep arrays inside inline tables on a single line#642
MsfPablo wants to merge 3 commits into
Boeing:feat/3.0from
MsfPablo:fix/tomlfmt-inline-table-array-single-line

Conversation

@MsfPablo

@MsfPablo MsfPablo commented Aug 4, 2026

Copy link
Copy Markdown

Summary

Fixes #631. printArray expanded a nested array whenever the enclosing inline table was estimated to exceed column_width, so an array written across several lines inside an inline table stayed multiline:

reqwest = { workspace = true, default-features = false, features = [
  "rustls",
] }

Per TOML v1.0 §5.2, an inline table is meant to occupy a single line — the line's width can't justify breaking one apart.

Fix

Force single-line printing for any array nested in an inline table, and dropped the inlineTableLineLen bookkeeping that existed only to drive the old expansion behavior. Arrays holding comments still expand, since collapsing them would move a comment onto the same line and comment out the rest of the table.

Test_TOML_InlineTableExpandsAtColumnWidth asserted the old (buggy) behavior and is replaced by Test_TOML_InlineTableArrayStaysSingleLine, plus a new regression test (Test_TOML_InlineTableArrayCollapsesFromMultiline) for the exact reported input, and fixture coverage (inline_table.input.toml/.expected.toml) for both a multiline array and a multiline array nested one inline table deeper.

Test plan

go test ./pkg/formatter/tomlfmt/... — all pass.

printArray expanded a nested array whenever the enclosing inline table was
estimated to exceed column_width, so an array written across several lines
inside an inline table stayed multiline:

    reqwest = { workspace = true, default-features = false, features = [
      "rustls",
    ] }

An inline table is meant to occupy a single line (TOML v1.0 §5.2), so the
width of the line cannot justify breaking one apart. Force single-line
printing for any array nested in an inline table and drop the
inlineTableLineLen bookkeeping, which existed only to drive that expansion.

Arrays holding comments keep expanding: collapsing them would move a
comment onto the same line and comment out the rest of the table.

Test_TOML_InlineTableExpandsAtColumnWidth asserted the old behavior and is
replaced by Test_TOML_InlineTableArrayStaysSingleLine, plus a regression
test for the reported input and fixture coverage for both a multiline
array and a multiline array nested one inline table deeper.

Fixes Boeing#631
@MsfPablo
MsfPablo requested a review from a team as a code owner August 4, 2026 19:15
@kehoecj kehoecj added OSS Community Contribution Contributions from the OSS Community waiting-on-maintainer-review PR is waiting to be reviewed and functionally tested by the maintainers labels Aug 4, 2026
@MsfPablo

Copy link
Copy Markdown
Author

Hi @kehoecj — just a friendly follow-up on this PR. It's been about a week with no review activity. Is there anything I can clarify or adjust to help move it forward? Happy to rebase, split the change, or rework the approach if there's a preferred style for this repo. Thanks!

@kehoecj kehoecj added pr-action-requested PR is awaiting feedback from the submitting developer and removed waiting-on-maintainer-review PR is waiting to be reviewed and functionally tested by the maintainers labels Aug 21, 2026

@kehoecj kehoecj left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for working on this @MsfPablo!

The fix is right for the short case but goes a bit too far for the long case. Right now it sets multiline = false unconditionally inside inline tables, which means arrays never expand regardless of line length. taplo (our reference tool) still expands when the total line exceeds column_width:

Short inline table — should stay on one line (your PR gets this right ✅):

# 73 chars total, fits fine
reqwest = { workspace = true, default-features = false, features = ["rustls"] }

Long inline table — taplo expands the array (your PR keeps it inline ❌):

# Input: 127 chars total
criterion = { version = "0.5", default-features = false, features = ["async_tokio", "html_reports", "plotters"] }

# taplo output:
criterion = { version = "0.5", default-features = false, features = [
  "async_tokio",
  "html_reports",
  "plotters",
] }

# This PR keeps it all on one line regardless of width

Could you change the multiline = false to something like multiline = (prefixLen + singleLineLen) > p.opts.ColumnWidth so it still respects the width threshold? That way short inline tables stay compact but long ones get the array expanded — matching what taplo does.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

OSS Community Contribution Contributions from the OSS Community pr-action-requested PR is awaiting feedback from the submitting developer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants