🚀 [Minor]: Format-Toml normalizes TOML to canonical form - #20
Merged
Marius Storhaug (MariusStorhaug) merged 5 commits intoJul 26, 2026
Merged
Conversation
This was referenced Jul 26, 2026
…oml-normalizer # Conflicts: # tests/Toml.Tests.ps1
…oml-normalizer # Conflicts: # README.md # tests/Toml.Tests.ps1
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.
Format-Tomlnormalizes TOML text into a canonical form — consistent key quoting, canonical scalar formatting, and stable table ordering — without changing its meaning. It is the single-call equivalent ofConvertFrom-Toml | ConvertTo-Toml, matching the pattern already established by sister modulesFormat-JsonandFormat-Hashtable.New:
Format-Tomlnormalizes TOML textFormat-Tomlaccepts a TOML string via pipeline (-InputObject), or reads a file via-Path(wildcard-aware) or-LiteralPath. It never writes back to the source file — output is always returned as a[string]. Formatting is idempotent: running it twice produces the same result as running it once, and the output always remains parseable byConvertFrom-Toml.TOML has no indentation semantics — nested tables are flat
[a.b]headers, not indented blocks. The-Indentparameter (default2) is a display convention: it prefixes nested table headers and their keys with spaces proportional to nesting depth, similar to how the Taplo formatter presents nested tables. Set-Indent 0to keep the flat, unindented form.Technical details
src/functions/public/Format-Toml.ps1, three parameter sets (InputObjectdefault/pipeline,Path,LiteralPath), reusesConvertFrom-Toml+ConvertTo-Toml— no new parser or emitter.src/functions/private/Add-TomlIndentation.ps1post-processes the canonical (flat)ConvertTo-Tomloutput to add depth-based indentation without touching the existing serializer, soConvertTo-Toml's own output and tests are unaffected.Describe 'Format-Toml'block totests/Toml.Tests.ps1covering: normalization, semantic equivalence toConvertFrom-Toml | ConvertTo-Toml, indentation at depth,-Indent 0flat output, idempotency, round-trip validity, pipeline input,-Path,-LiteralPath, and error handling for invalid TOML / missing files.examples/General.ps1updated with aFormat-Tomlusage section.Format-Tmlalias mentioned in Add Format-Toml function for normalization #3 — the module has no established alias-export mechanism yet (build.ps1only exports functions), so adding one alias in isolation would be inconsistent with the rest of the public surface. Can be revisited once alias support lands.Format-Tomladded with tests, README/examples updated. Alias task intentionally deferred (see above).pwsh -File .\build.ps1thenInvoke-Pester -Path .\tests\Toml.Tests.ps1 -CI→ 132/132 passing.PSScriptAnalyzerclean on new files (aside from a pre-existing, module-widePSUseBOMForUnicodeEncodedFileinconsistency already present on most files).Relevant issues (or links)