---
title: tb fmt
meta:
    description: Formats a .datasource or .pipe file
---

## tb fmt

Formats a .datasource or .pipe file. .connection files are not *yet* supported.

These are the options available for the `fmt` command:

{% table %}
  * Option
  * Description
  ---
  * --line-length INTEGER
  * A number indicating the maximum characters per line in the node SQL, lines split based on the SQL syntax and the number of characters passed as a parameter.
  ---
  * --dry-run
  * Don't ask to overwrite the local file.
  ---
  * --yes
  * Don't ask for confirmation to overwrite the local file.
  ---
  * --diff
  * Outputs correctly formatted block (if differs from local file) and prompts to apply correction to local file.
{% /table %}

This command applies opinionated formatting rules and may reorder file properties for consistency. For example, these properties:

```tb
ENGINE "MergeTree"
ENGINE_SORTING_KEY "name"
ENGINE_PARTITION_KEY "name"
```

will be formatted as:

```tb
ENGINE MergeTree
ENGINE_PARTITION_KEY name
ENGINE_SORTING_KEY name
```

This command removes comments starting with \# from the file, so use DESCRIPTION or a comment block instead:

```sql {% title="Example comment block" %}
%
{\% comment this is a comment and fmt keeps it %}

SELECT
  {\% comment this is another comment and fmt keeps it %}
  count() c
FROM stock_prices_1m
```
{% callout %}
You can add `tb fmt` to your git `pre-commit` hook to have your files properly formatted. If the SQL formatting results aren't what you expect, you can disable it just for the blocks needed. Read [how to disable fmt](https://docs.sqlfmt.com/getting-started/disabling-sqlfmt).
{% /callout %}
