Auto Sorting

One of Tombi's most distinctive features is automatic sorting. It can automatically sort content including comments, using its own unique treatment of comments.

💡Tip

Tombi cannot insert empty newlines between key-value pairs, but that is a trade-off for automatic sorting.

# BEFORE
key1 = "value1"

key2 = "value2"

# AFTER
key1 = "value1"
key2 = "value2"

If you would like to have a blank line between key-value pairs, we recommend inserting an empty comment line. For example:

key1 = "value1"
#
# ↑ Add an empty comment line here for separation instead of newlines
key2 = "value2"

This way, Tombi's formatter will preserve the separation without interfering with auto sorting.

⚠️Warning

If you don't like the automatic sorting provided by Tombi, we recommend disabling the formatter, and instead using another formatter such as dprint that meets your requirements.

[lsp]
formatting.enabled = false

Using Tombi's formatter without the auto-sorting feature is extremely high-maintenance. To bypass the default sorting, you must either add comment directives throughout your code, or build and maintain your own JSON Schema.

How to Specify Auto-Sorting Methods

Tombi does not perform automatic sorting unless a sorting method is specified.

Auto-sorting methods are available in the following order of priority:

Comment Directives

You can specify auto-sorting methods using comment directives. This has higher priority than JSON Schema specifications.

⚠️Warning

This is intended for projects that are not large enough to warrant creating a JSON Schema, or as a temporary workaround for errors in JSON Schemas registered in the Schema Store.

JSON Schema

This is probably the method you'll benefit from the most.

When schemas automatically retrieved from the JSON Schema Store contain the following keys, automatic sorting is performed according to that schema:

Files like Cargo.toml and pyproject.toml registered in the JSON Schema Store have these keys specified.

Additionally, you can specify JSON Schema files using configuration files or comment directives, allowing you to apply schemas from sources other than the JSON Schema Store.