|
4 | 4 |
|
5 | 5 | Prettier is an opinionated code formatter. It enforces a consistent style by parsing your code and re-printing, taking various rules into account. |
6 | 6 |
|
7 | | -This plugin adds support for `toml` through [taplo][]. |
| 7 | +This plugin adds support for `toml` through [tombi][]. |
8 | 8 |
|
9 | 9 | ## Notice |
10 | 10 |
|
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. |
12 | 12 | Of course it should just work, but may not match [prettier][]'s format sometimes. |
13 | 13 |
|
14 | 14 | ## Requirements |
15 | 15 |
|
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+). |
17 | 17 |
|
18 | 18 | ## Install |
19 | 19 |
|
@@ -47,35 +47,88 @@ npx prettier --write foo.toml |
47 | 47 | yarn prettier --write foo.toml |
48 | 48 | ``` |
49 | 49 |
|
| 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 | + |
50 | 81 | ## Parser Options |
51 | 82 |
|
| 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 | + |
52 | 95 | ```ts |
53 | 96 | 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` |
79 | 132 | } |
80 | 133 | ``` |
81 | 134 |
|
@@ -107,4 +160,5 @@ Detailed changes for each release are documented in [CHANGELOG.md](./CHANGELOG.m |
107 | 160 | [mit]: http://opensource.org/licenses/MIT |
108 | 161 | [prettier]: https://prettier.io |
109 | 162 | [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 |
0 commit comments