CI Integration
GitHub Actions
Check formatting on PRs
name: SQL Format Check
on: [pull_request]
jobs:
format-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Check SQL formatting
run: dfmt --check
Format only changed files
- name: Check changed SQL files
run: dfmt --changed-since origin/main --check
Pre-commit Hook
Add to .pre-commit-config.yaml:
repos:
- repo: local
hooks:
- id: dfmt
name: dfmt
entry: dfmt --check
language: system
types: [sql]
Or format changed files only:
#!/bin/sh
# .git/hooks/pre-commit
dfmt --changed-since HEAD --check
--check Mode
dfmt --check exits with code 1 if any file would be reformatted, and code 0 if all files are already formatted. It prints which files would change:
42 files checked, 3 would be reformatted, 39 already formatted, 0 failed (1203 ms)
No files are modified in --check mode.
--changed-since for PRs
--changed-since uses git diff --name-only to find changed .sql files. Common patterns:
# Files changed vs main branch
dfmt --changed-since main --check
# Files changed vs upstream
dfmt --changed-since origin/main --check
# Files changed in last commit
dfmt --changed-since HEAD~1 --check
The changed files are intersected with the include/exclude patterns from .dfmt.json, so only files that are part of your project are checked.