A Prettier plugin for formatting TOML files, powered by taplo. Current stable version is 2.0.6 (released December 2024, part of the un-ts monorepo with frequent releases). It supports Prettier v3 and requires Node >=16. Differentiators: aligns with Prettier's opinionated style, offers many formatting options (alignEntries, reorderKeys, compactArrays, etc.), ships TypeScript types, and is actively maintained. Unlike standalone TOML formatters, this integrates as a Prettier plugin, allowing consistent formatting across multiple languages.
npm install prettier-plugin-tomlVerified import paths — ran on the pinned version, not inferred.
Demonstrates installation, plugin configuration in .prettierrc, and execution via CLI.
Upgrade Prettier to v3 (npm i -D prettier@latest). Note that plugin options may differ from v2.
Use default import (import p from 'prettier-plugin-toml') or specify the plugin in Prettier config's plugins array by string name.
Adjust plugin-specific options (indentTables, alignEntries, etc.) to better match your project's Prettier configuration.
Upgrade Node to version 16.0.0 or later.
Review the option documentation and test formatting on sample TOML files to ensure desired behavior.
Set compactInlineTables: true in Prettier options if desired.
Set reorderKeys: false unless you intentionally want key sorting.
Run npm i -D prettier-plugin-toml in the project root and ensure node_modules contains it.
Ensure you use prettier-plugin-toml v2+ and indicate plugin in .prettierrc as 'prettier-plugin-toml', not as a require or import in the config.
Check that prettier-plugin-toml is listed in the .prettierrc 'plugins' array and that Prettier is v3+.
Validate the TOML syntax using a linter (e.g., toml-lint) before running Prettier.