# Enforce SQL and YAML Best Practices

Paradime offers integrated tools like SQLFluff and Prettier to help enforce best practices for SQL and YAML files, ensuring high-quality code and reducing errors in your dbt™ project.\
\
**Estimated completion time:** 20 minutes

{% hint style="warning" %}

### Prerequisites

* [A dbt™ project set up in Paradime](/app-help/guides/paradime-101/getting-started-with-the-paradime-ide/setting-up-a-dbt-project.md)
* [At least one .sql and .yml file in your dbt™ project](https://docs.paradime.io/app-help/guides/paradime-101/getting-started-with-the-paradime-ide/utilizing-advanced-developer-features/pages/xnzMpxvtdDSGzR3giyID#id-4.-materialize-your-dbt-tm-model)
* Basic understanding of SQL and YAML syntax
  {% endhint %}

### What You'll Learn

In this guide, you'll learn how to:

* Use SQLFluff to lint and format SQL files
* Utilize Prettier to format and debug your YAML files
* Customize settings for both tools to match your team's standards

***

### 1. SQLFluff

SQLFluff is an integrated linting tool in Paradime that helps maintain consistent, high-quality SQL code. The [pre-configured template](/app-help/documentation/integrations/code-ide/sql-fluff.md#set-your-configuration-file-by-adding-supported-rules) is for Snowflake and dbt, setting basic rules for SQL formatting such as line length, indentation, aliasing, and capitalization. It provides a foundation for consistent SQL styling that can be easily customized to fit specific project needs.

{% embed url="<https://youtu.be/RVCTo8fX-7Q>" %}

**Key Features:**

* **Integrated Linting**: Automatically check SQL code against standard or custom rules.
* **Pre-configured for dbt™**: Comes ready to use with basic rules tailored for dbt™ projects.
* **Real-time Formatting**: Use the 'Prettier' button in Paradime's IDE for instant code corrections.

**How to Use SQLFluff:**

1. Select a .sql file within your dbt™ project.
2. Click the `Prettier` button in the commands panel to automatically format your .yml file.

<figure><img src="/files/OxKBuVbFsSi1fod6ahh5" alt=""><figcaption></figcaption></figure>

3. **Optional:** Customize your SQL formatting by creating a .sqlfluff file in your dbt™ root directory (this is in the same directory where your dbt\_project.yml lives).

<figure><img src="/files/oaBRoQf4I9fyKoHo0bMz" alt=""><figcaption></figcaption></figure>

{% hint style="warning" %}
If you don't have a `.sqlfluff` file in your project,  simply create new file with the exact name ".sqlfluff" in the same directory where your `dbt_project.yml` lives.
{% endhint %}

#### Example SQLFluff Formatting

{% tabs %}
{% tab title="Before Formatting" %}

```sql
WITH player_info AS (SELECT * FROM {{ ref('nba_player_info') }})
, player_salaries AS (SELECT player_id, salary, season FROM {{ ref('nba_player_salaries') }})
, joined AS (SELECT pi.*, ps.salary, ps.season FROM player_info AS pi LEFT JOIN player_salaries AS ps ON pi.player_id = ps.player_id)
SELECT * FROM joined
```

{% endtab %}

{% tab title="After Formatting with SQLFluff:" %}

```sql
with player_info as (
    select *
    from {{ ref('nba_player_info') }}
),
player_salaries as (
    select
        player_id,
        salary,
        season
    from {{ ref('nba_player_salaries') }}
),
joined as (
    select
        pi.*,
        ps.salary,
        ps.season
    from player_info as pi
    left join player_salaries as ps on pi.player_id = ps.player_id
)

select *
from joined
```

{% endtab %}
{% endtabs %}

***

### 2. Prettier

Prettier is an integrated code formatter in Paradime that helps maintain consistent, error-free YAML files in your dbt™ project. Prettier comes pre-installed in your project and uses default configurations provided by the [Prettier library](https://prettier.io/docs/en/configuration.html), which can be easily customized to fit specific YAML preferences.&#x20;

{% embed url="<https://youtu.be/vqh9M6rYB7A>" %}

**Key Features:**

* **Automatic Formatting**: Formats YAML files for improved readability and code quality.
* **Error Detection**: Highlights severe formatting errors and assists in debugging.
* **Customization**: Allows custom configurations through a .prettierrc file.

**How to Use:**

1. Select a .yml file within your dbt™ project.
2. Click the `Prettier` button in the commands panel to automatically format your .yml file.

<figure><img src="/files/OxKBuVbFsSi1fod6ahh5" alt=""><figcaption></figcaption></figure>

3. If more severe errors are detected, click the `Prettier` button in the toolbar to debug.

<figure><img src="/files/C2bALCYnpp7ImGXqHxm7" alt=""><figcaption></figcaption></figure>

4. **Optional**: Customize your YAML formatting by creating a .prettierrc file in your dbt™ root directory (this is in the same directory where your dbt\_project.yml lives).

<figure><img src="/files/22GGNWGaDjaX2PbAMVfJ" alt=""><figcaption></figcaption></figure>

#### Example YAML Formatting

{% tabs %}
{% tab title="Before formatting" %}

```yaml
version: 2

models:
  - name: nba_player_info
    columns:
      - name: player_id
        tests:
          -   unique
          - not_null
      - name: first_name
      - name: last_name
      - name: team_name
      - name: position

      - name:   height
      - name: weight
  - name: nba_player_salaries
    columns:
      - name: player_id
      - name: player_name
      - name: salary
      - name:   season

```

{% endtab %}

{% tab title="After Applying Prettier" %}

```yaml
version: 2

models:
  - name: nba_player_info
    columns:
      - name: player_id
        tests:
          - unique
          - not_null
      - name: first_name
      - name: last_name
      - name: team_name
      - name: position
      - name: height
      - name: weight
  - name: nba_player_salaries
    columns:
      - name: player_id
      - name: player_name
      - name: salary
      - name: season
```

{% endtab %}
{% endtabs %}

***

{% hint style="info" %}

### Related Documentation

* [SQL Fluff](/app-help/documentation/integrations/code-ide/sql-fluff.md)
* [Code Quality](/app-help/documentation/code-ide/command-panel/code-quality.md)
* [Prettier](/app-help/documentation/integrations/code-ide/prettier.md)
  {% endhint %}

***

### Summary

By using SQLFluff and Prettier in Paradime, you enforce best practices across your SQL and YAML files. These tools help maintain consistent, clean, and high-quality code, improving your project's readability and reducing errors. Customize them to fit your team's coding standards, streamline your workflow, and keep your dbt™ project error-free.

Next, we'll explore [how to work with CSV files in Paradime](/app-help/guides/paradime-101/getting-started-with-the-paradime-ide/utilizing-advanced-developer-features/working-with-csv-files.md).


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.paradime.io/app-help/guides/paradime-101/getting-started-with-the-paradime-ide/utilizing-advanced-developer-features/enforce-sql-and-yaml-best-practices.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
