Add TOML version catalog formatter step#2917
Open
mkutz wants to merge 5 commits intodiffplug:mainfrom
Open
Conversation
Add a dedicated FormatterStep for formatting and sorting Gradle version catalog files (libs.versions.toml). The step normalizes spacing around operators and inside inline tables/arrays, sorts entries alphabetically, and orders tables canonically ([versions], [libraries], [bundles], [plugins]).
- Preserve comments inside sections by attaching them to the entry below, so they travel with the entry during sorting - Strip and re-attach inline comments (# ...) before formatting inline tables/arrays - Preserve blank lines in the file preamble - Sort entries by logical key name, stripping surrounding quotes - Add TODO.md documenting remaining TOML spec edge cases
Adds a stripQuotedKeys parameter (default false) that removes unnecessary quotes from keys when the unquoted form is a valid bare TOML key. Keys like "foo.bar" that would change semantics are preserved.
- Parse multi-line inline tables by tracking brace/bracket depth and joining continuation lines into a single entry - Add configurable maxLineLength (default 120): lines exceeding the limit split their inline table across multiple lines (one pair per line, 2-space indent, trailing commas); multi-line tables that fit are joined into a single line - Update TODO.md with fixed items
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.
Resolves #2916
Adds a dedicated
FormatterStepfor formatting and sorting Gradle version catalog (.toml) files, with no external dependencies.Features
=and inside inline tables{ }and arrays[ ][versions],[libraries],[bundles],[plugins]maxLineLength(default 120, configurable) — long inline tables are split across lines (one pair per line, 2-space indent, trailing commas)stripQuotedKeys(opt-in, default false) — removes unnecessary quotes from keys when the bare form is validUsage
Gradle:
spotless { toml { target 'gradle/libs.versions.toml' versionCatalog() // or with options: // versionCatalog { maxLineLength(80); stripQuotedKeys(true) } } }Maven:
Known limitations
Documented in
lib/src/main/java/com/diffplug/spotless/toml/TODO.md. These are valid TOML constructs that won't appear in typical Gradle version catalogs:=Checklist
Step(VersionCatalogStep)createmethod returningFormatterStepVersionCatalogStepTestusingStepHarnessSerializableEqualityTesterCHANGES.mdfilesspotlessApplycleanspotbugsMainclean