# Paradime Setup and Configuration

## **Overview**

Paradime comes pre-installed with pre-commits, making it easy to get started with code quality checks. You only need to configure the hooks you want to use, and Paradime handles the rest.

## **Getting Started**

To get started, Run `paradime pre-commit` in the terminal

<figure><img src="https://2337193041-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHET0AD04uHMgdeLAjptq%2Fuploads%2FzfZrT4Oh61MDYdZVtCCr%2Fimage.png?alt=media&#x26;token=6c95b4e6-92e0-48c2-85bd-d820a97fa267" alt=""><figcaption></figcaption></figure>

## **Initial Setup**

If your repository doesn't have existing pre-commit configurations, Paradime offers standard recommended hooks to get you started.&#x20;

These include:

* [SQL formatting and linting using SQLFluff](https://docs.paradime.io/app-help/documentation/integrations/code-ide/pre-commit/sqlfluff-hooks)
* [dbt models checks using dbt-checkpoint](https://docs.paradime.io/app-help/documentation/integrations/code-ide/pre-commit/dbt-tm-checkpoint-hooks)
* [YAML validation using Prettier](https://docs.paradime.io/app-help/documentation/integrations/code-ide/pre-commit/prettier-hooks)
* General code quality checks

**Example pre commit hooks template**

{% code title=".pre-commit-config.yaml" lineNumbers="true" %}

```yaml
# Auto-update the config to the latest repos' versions by executing "pre-commit autoupdate"
# For more dbt pre-commit hooks check https://docs.paradime.io/app-help/documentation/integrations/code-ide/pre-commit

repos:
  # YAML formatting using Prettier
  - repo: https://github.com/pre-commit/mirrors-prettier
    rev: v3.1.0
    hooks:
      - id: prettier
        types: [yaml] # Only run on YAML files
        additional_dependencies:
          - prettier@3.1.0
        args: [--write]

  # Standard pre-commit hooks
  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v5.0.0
    hooks:
      - id: trailing-whitespace
        name: Trim Trailing Whitespace
        description: Removes trailing whitespace from all files
        files: ^.*\.(sql|yml|yaml|md)$
      - id: end-of-file-fixer
        name: Fix End of Files
        description: Ensures files end with a newline
        files: ^.*\.(sql|yml|yaml|md)$
      - id: check-added-large-files
        name: Check for Large Files
        description: Prevents giant files from being committed
        args: ["--maxkb=500"]

  # SQL formatting using SQLFluff
  - repo: https://github.com/sqlfluff/sqlfluff
    rev: 3.3.0
    hooks:
      - id: sqlfluff-lint
        name: SQLFluff Lint
        description: Lints SQL files using SQLFluff
        files: ^.*\.sql$
        additional_dependencies: ["sqlfluff-templater-dbt"]
        args: ["--dialect", "bigquery", "--templater", "dbt"]
      - id: sqlfluff-fix
        name: SQLFluff Fix
        description: Auto-fixes SQL files using SQLFluff
        files: ^.*\.sql$
        additional_dependencies: ["sqlfluff-templater-dbt"]
        args: ["--dialect", "bigquery", "--templater", "dbt"]

  # dbt™️ specific checks
  - repo: https://github.com/dbt-checkpoint/dbt-checkpoint
    rev: v2.0.6
    hooks:
      # Model checks
      - id: check-model-has-description
        name: Check Model Descriptions
        description: Ensures models have descriptons
      - id: check-model-has-tests
        name: Check Model Tests
        description: Ensures models have minimum test coverage
        args: ["--test-cnt", "2"]

      # Script checks
      - id: remove-script-semicolon
        name: Remove Script Semicolon
        description: Remove semicolons at the end of the script
        files: models/.*\.sql$
      - id: check-script-has-no-table-name
        name: Check Script Table References
        description: Ensure only source() or ref() macros are used for table references
        files: models/.*\.sql$
      - id: check-script-ref-and-source
        name: Check Script References
        description: Validate all ref() and source() references exist
        files: models/.*\.sql$
        args: [--manifest, target/manifest.json]
      - id: dbt-parse

# Define what files to exclude from all hooks
exclude: |
  (?x)^(
      target/.*|
      logs/.*|
      .*/snapshots/.*|
      tests/.*_test\.sql|
      analysis/.*
  )$
```

{% endcode %}

## **Running Pre-commit**

You can run pre-commit checks in two ways:

1. **All Files**: Run checks on all files in your project
2. **Staged Files**: Run checks only on files staged for commit

To run checks, use the same command and select the option from the menu:

```bash
paradime pre-commit
```

<figure><img src="https://2337193041-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FHET0AD04uHMgdeLAjptq%2Fuploads%2FKx08Q9UJovhatoANbt5K%2Fimage.png?alt=media&#x26;token=56ebebf1-8b6b-442c-b07e-a5fdef231d6c" alt=""><figcaption></figcaption></figure>

## **First-Time Installation**

{% hint style="info" %}
Note: When running pre-commits for the first time, Paradime will install all necessary hooks. This initial setup might take a minute to complete as it downloads and configures the required components.
{% endhint %}

**Automatic Pre-commit Checks**

To enable automatic pre-commit checks when creating commits via terminal, run:

```bash
pre-commit install
```

{% hint style="warning" %}
**Important:** This is recommended only if you use git in the terminal to create commits. For commits made through Git Lite or Git Advanced panel, hook errors/warnings are not currently displayed.
{% endhint %}

To disable automatic pre-commit checks when creating commits via terminal,  run:

```bash
pre-commit uninstall
```

**Best Practices**

1. Start with Paradime's recommended hooks
2. Gradually customize configurations as needed
3. Run checks manually before committing large changes
4. Keep hook configurations in version control

**Common Workflows**

1. **Manual Check Before Commit**

```bash
paradime pre-commit
# Review and fix any issues
git commit -m "Your message"
```

2. **Checking Specific Files**

```bash
git add your_files
paradime pre-commit
```

3. **Updating Hook Configurations**

* Modify `.pre-commit-config.yaml`
* Auto-update the config to the latest repos' versions by executing `pre-commit autoupdate`&#x20;
* Run `paradime pre-commit` to apply changes

Remember: Paradime's pre-commit integration makes it easy to maintain code quality without complex setup or configuration steps.
