Skip to content

Commit e2e5c97

Browse files
authored
feat(prettier-plugin-toml): replace taplo with tombi (#519)
1 parent 02f37a2 commit e2e5c97

18 files changed

Lines changed: 1349 additions & 140 deletions

‎.changeset/tombi-toml-formatter.md‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
"prettier-plugin-toml": major
3+
---
4+
5+
feat(prettier-plugin-toml)!: replace the unmaintained [`taplo`](https://github.com/tamasfe/taplo) with [`tombi`](https://github.com/tombi-toml/tombi)
6+
7+
The parser/printer is now powered by `@tombi-toml/wasm-lib`, which supports TOML
8+
`v1.0.0` and `v1.1.0` and fixes the crashes reported in
9+
[#487](https://github.com/un-ts/prettier/issues/487).
10+
11+
- Prettier's core options are inherited and mapped to tombi: `printWidth` →
12+
`line-width`, `tabWidth` → `indent-width`, `useTabs` → `indent-style`,
13+
`singleQuote` → `string-quote-style` and `bracketSpacing` →
14+
`inline-table-brace-space-width`. `endOfLine` keeps being handled by Prettier.
15+
- The previous `taplo` options (`alignEntries`, `alignComments`,
16+
`arrayAutoExpand`, `arrayAutoCollapse`, `compactArrays`,
17+
`compactInlineTables`, `compactEntries`, `indentTables`, `indentEntries`,
18+
`reorderKeys` and `allowedBlankLines`) are replaced by tombi's own options.
19+
- Tombi's own configuration (`.tombi.toml`, `tombi.toml`, `.config/tombi.toml`
20+
and `[tool.tombi]` in `pyproject.toml`) is picked up following
21+
[Tombi's search priority](https://tombi-toml.github.io/tombi/docs/configuration).
22+
The discovered `[format.rules]` override Prettier's defaults, while explicitly
23+
set Prettier options override the discovered config.
24+
- Node.js `v18.0.0` or later is required.
25+
26+
Tombi's schema lookup is always disabled, and discovered configuration files are
27+
watched so edits to them are picked up without restarting the process.
28+
29+
See the `prettier-plugin-toml` README for the full list of supported options.

‎eslint.config.js‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ import tsdoc from 'eslint-plugin-tsdoc'
55
export default [
66
...base,
77
{
8-
ignores: ['**/src/languages.ts'],
8+
ignores: [
9+
'**/src/languages.ts',
10+
// Intentionally invalid TOML used to test error reporting.
11+
'packages/toml/test/fixtures/invalid.toml',
12+
],
913
},
1014
{
1115
plugins: {

‎packages/toml/README.md‎

Lines changed: 83 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44
55
Prettier is an opinionated code formatter. It enforces a consistent style by parsing your code and re-printing, taking various rules into account.
66

7-
This plugin adds support for `toml` through [taplo][].
7+
This plugin adds support for `toml` through [tombi][].
88

99
## Notice
1010

11-
This plugin is still under development, its printer just wraps [taplo][]'s default printer.
11+
This plugin is still under development, its printer just wraps [tombi][]'s default printer.
1212
Of course it should just work, but may not match [prettier][]'s format sometimes.
1313

1414
## Requirements
1515

16-
`prettier-plugin-toml` is an evergreen module. 🌲 This module requires an [LTS](https://github.com/nodejs/Release) Node version (v16.0.0+).
16+
`prettier-plugin-toml` is an evergreen module. 🌲 This module requires an [LTS](https://github.com/nodejs/Release) Node version (v18.0.0+).
1717

1818
## Install
1919

@@ -47,35 +47,88 @@ npx prettier --write foo.toml
4747
yarn prettier --write foo.toml
4848
```
4949

50+
## Configuration
51+
52+
Besides the options below, this plugin reads [tombi][]'s own configuration,
53+
following its [search priority][tombi-config]:
54+
55+
1. **Project** — for each directory from the formatted file's directory up to
56+
the filesystem root: `.tombi.toml`, `tombi.toml`, `.config/tombi.toml`, then
57+
`[tool.tombi]` in `pyproject.toml`.
58+
2. **User** — `$XDG_CONFIG_HOME/tombi/config.toml`,
59+
`~/.config/tombi/config.toml`, plus the platform specific
60+
`~/Library/Application Support/tombi/config.toml` (macOS) or
61+
`%APPDATA%\tombi\config.toml` (Windows).
62+
3. **System** — `/etc/tombi/config.toml`.
63+
64+
The rules are resolved in order, each step overriding the previous one:
65+
66+
1. Tombi's and Prettier's defaults.
67+
2. The discovered configuration's `[format.rules]`.
68+
3. Prettier options that are explicitly set — a value equal to Prettier's
69+
default (for example `printWidth: 80`) does not count as explicit.
70+
4. The discovered configuration's per-file `[[overrides]]`, applied by Tombi
71+
last.
72+
73+
### Notes
74+
75+
- Tombi's schema lookup is always disabled, so formatting stays offline and
76+
deterministic.
77+
- Discovered configuration files are cached per directory and polled (best
78+
effort), so edits to them apply without restarting the process. A newly
79+
created project configuration applies on the next run.
80+
5081
## Parser Options
5182

83+
[prettier][]'s own core options are inherited and mapped to their tombi
84+
counterparts where they exist:
85+
86+
- `printWidth` → `line-width`
87+
- `tabWidth` → `indent-width`
88+
- `useTabs` → `indent-style`
89+
- `singleQuote` → `string-quote-style`
90+
- `bracketSpacing` → `inline-table-brace-space-width`
91+
92+
`endOfLine` is handled by [prettier][] itself. All of tombi's other format rules
93+
are exposed as `toml` options and can be used to override the inherited values:
94+
5295
```ts
5396
interface PrettierOptions {
54-
// 'Align consecutive entries vertically.'
55-
alignEntries: boolean // default `false`
56-
// Align consecutive comments after entries and items vertically. This applies
57-
// to comments that are after entries or array items.
58-
alignComments: boolean // default `true`
59-
// Expand arrays to multiple lines that exceed the maximum column width.
60-
arrayAutoExpand: boolean // default `true`
61-
// Collapse arrays that don't exceed the maximum column width and don't
62-
// contain comments.
63-
arrayAutoCollapse: boolean // default `true`
64-
// Omit white space padding from single-line arrays.
65-
compactArrays: boolean // default `true`
66-
// Omit white space padding from the start and end of inline tables.
67-
compactInlineTables: boolean // default `false`
68-
// Omit white space around `=`.
69-
compactEntries: boolean // default `false`
70-
// Indent based on tables and arrays of tables and their subtables, subtables
71-
// out of order are not indented.
72-
indentTables: boolean // default `false`
73-
// Indent entries under tables.
74-
indentEntries: boolean // default `false`
75-
// Alphabetically reorder keys that are not separated by empty lines.
76-
reorderKeys: boolean // default `false`
77-
// The maximum number of allowed blank lines between entries and tables.
78-
allowedBlankLines: number // integer, default `1`
97+
// The TOML version to use when parsing and formatting.
98+
tomlVersion: 'v1.0.0' | 'v1.1.0-preview' | 'v1.1.0' // default `v1.0.0`
99+
// The number of spaces inside the brackets of a single line array.
100+
arrayBracketSpaceWidth: number // default `0`
101+
// The number of spaces after the comma in a single line array.
102+
arrayCommaSpaceWidth: number // default `1`
103+
// The style used to format comments.
104+
commentStyle: 'normalize' | 'preserve' // default `normalize`
105+
// The delimiter between date and time.
106+
dateTimeDelimiter: 'preserve' | 'space' | 'T' // default `T`
107+
// The blank lines limit between groups.
108+
groupBlankLinesLimit: number // default `1`
109+
// Whether to indent sub-tables.
110+
indentSubTables: boolean // default `false`
111+
// Whether to indent table key-value pairs.
112+
indentTableKeyValuePairs: boolean // default `false`
113+
// The number of spaces inside the braces of a single line inline table,
114+
// defaults to `bracketSpacing` (`1` or `0`).
115+
inlineTableBraceSpaceWidth: number // default `bracketSpacing`
116+
// The number of spaces after the comma in a single line inline table.
117+
inlineTableCommaSpaceWidth: number // default `1`
118+
// Whether to align the equals sign in key-value pairs.
119+
keyValueEqualsSignAlignment: boolean // default `false`
120+
// The preferred quote character for keys, defaults to `stringQuoteStyle`.
121+
keyQuoteStyle: 'double' | 'preserve' | 'single' // default `undefined`
122+
// The preferred quote character for strings, defaults to `singleQuote`.
123+
stringQuoteStyle: 'double' | 'preserve' | 'single' // default `singleQuote`
124+
// Whether to align the trailing comments in key-value pairs.
125+
trailingCommentAlignment: boolean // default `false`
126+
// The number of spaces around the equals sign in a key-value pair.
127+
keyValueEqualsSignSpaceWidth: number // default `1`
128+
// The number of blank lines between tables.
129+
tableBlankLines: number // default `1`
130+
// The number of spaces before a trailing comment.
131+
trailingCommentSpaceWidth: number // default `2`
79132
}
80133
```
81134

@@ -107,4 +160,5 @@ Detailed changes for each release are documented in [CHANGELOG.md](./CHANGELOG.m
107160
[mit]: http://opensource.org/licenses/MIT
108161
[prettier]: https://prettier.io
109162
[ray]: https://github.com/so1ve
110-
[taplo]: https://github.com/tamasfe/taplo
163+
[tombi]: https://github.com/tombi-toml/tombi
164+
[tombi-config]: https://tombi-toml.github.io/tombi/docs/configuration

‎packages/toml/package.json‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"funding": "https://opencollective.com/unts",
1313
"license": "MIT",
1414
"engines": {
15-
"node": ">=16.0.0"
15+
"node": ">=18.0.0"
1616
},
1717
"main": "./lib/index.cjs",
1818
"types": "./index.d.cts",
@@ -41,7 +41,9 @@
4141
"prettier": "^3.0.3"
4242
},
4343
"dependencies": {
44-
"@taplo/lib": "^0.5.0"
44+
"@dual-bundle/import-meta-resolve": "^4.2.1",
45+
"@tombi-toml/wasm-lib": "^1.5.5",
46+
"smol-toml": "^1.8.0"
4547
},
4648
"publishConfig": {
4749
"access": "public"

0 commit comments

Comments
 (0)