taplo.toml

Overview

The taplo.toml file is a configuration file used to define formatting and linting rules specifically for TOML files within a project. It sets global include patterns for which files to process, and provides detailed formatting rules and key reorder policies, especially tailored for Rust project manifest files such as Cargo.toml. The file primarily focuses on controlling how arrays and keys are ordered, how inline tables are expanded, and which files or sections these rules apply to.

Configuration Details

Global Include Pattern

include = ["**/*.toml"]

Formatting Section

[formatting]
reorder_arrays = false
indent_string = "    "

Rule Definitions

The file contains multiple [[rule]] tables, each defining specific formatting rules that apply conditionally based on the file path or keys.

Rule 1: For All Cargo.toml Files

[[rule]]
include = ["**/Cargo.toml"]
formatting.inline_table_expand = false

Rule 2: For Dependencies Sections in Cargo.toml

[[rule]]
include = ["**/Cargo.toml"]
keys = ["dependencies", "*-dependencies", "workspace.dependencies"]
[rule.formatting]
reorder_keys = true

Rule 3: For Root Cargo.toml Workspace Members

[[rule]]
include = ["Cargo.toml"]
keys = ["workspace", "members"]
formatting.reorder_arrays = true

Implementation Details and Algorithms

Interaction with Other Parts of the System

Usage Examples

Example: Dependency Section Before and After Formatting

Before:

[dependencies]
serde = "1.0"
rand = "0.8"

After (with reorder_keys = true):

[dependencies]
rand = "0.8"
serde = "1.0"

Example: Workspace Members Array Before and After Formatting

Before:

[workspace]
members = [
    "crate-b",
    "crate-a"
]

After (with reorder_arrays = true):

[workspace]
members = [
    "crate-a",
    "crate-b"
]

Visual Diagram

flowchart TD
A[Global Include: "**/*.toml"] --> B[Formatting Settings]
B --> B1[reorder_arrays: false]
B --> B2[indent_string: "    "]
A --> C[Rule 1: Cargo.toml]
C --> C1[inline_table_expand: false]
A --> D[Rule 2: Cargo.toml Dependencies]
D --> D1[keys: dependencies, *-dependencies, workspace.dependencies]
D --> D2[reorder_keys: true]
A --> E[Rule 3: Root Cargo.toml Workspace]
E --> E1[keys: workspace, members]
E --> E2[reorder_arrays: true]

This diagram shows the hierarchical structure of the global inclusion and the three main rule sets with their respective formatting configurations.