scaf fmt
scaf fmt
Section titled “scaf fmt”The fmt command formats scaf files to a consistent style.
Basic Usage
Section titled “Basic Usage”# Format all .scaf files in current directoryscaf fmt
# Format specific filescaf fmt queries/users.scaf
# Format files in a directoryscaf fmt ./queries/Options
Section titled “Options”--write, -w
Section titled “--write, -w”Write changes back to files (default: false):
# Preview changes (dry run)scaf fmt queries/users.scaf
# Apply changesscaf fmt --write queries/users.scafscaf fmt -w queries/users.scaf--check
Section titled “--check”Exit with error if files need formatting (useful for CI):
scaf fmt --checkReturns exit code 1 if any files would change.
--diff
Section titled “--diff”Show diff of changes:
scaf fmt --diff queries/users.scafFormatting Rules
Section titled “Formatting Rules”Indentation
Section titled “Indentation”Two spaces for all indentation:
GetUser { group "tests" { test "example" { $userId: 1
u.name: "Alice" } }}Blank Lines
Section titled “Blank Lines”- One blank line between top-level elements (queries, setup, scopes)
- One blank line between groups
- One blank line between tests in a group
- Blank line between inputs and outputs in a test
fn GetUser `...`
fn CreateUser `...`
setup `...`
GetUser { group "first" { test "a" { $userId: 1
u.name: "Alice" }
test "b" { $userId: 2
u.name: "Bob" } }
group "second" { test "c" { ... } }}Query Bodies
Section titled “Query Bodies”Query bodies are formatted as-is (preserving your SQL/Cypher formatting):
fn GetUser `MATCH (u:User {id: $userId})RETURN u.name, u.email, u.age`Comments
Section titled “Comments”Comments are preserved and aligned:
// This is a top-level commentfn GetUser `...`
GetUser { // Group comment group "tests" { test "example" { $userId: 1 // Inline comment
u.name: "Alice" } }}Statement Alignment
Section titled “Statement Alignment”Colons in statements are aligned within a block:
test "aligned" { $userId: 1 $includeDeleted: false
u.name: "Alice" u.email: "alice@example.com" u.verified: true}CI Integration
Section titled “CI Integration”GitHub Actions
Section titled “GitHub Actions”- name: Check formatting run: scaf fmt --checkPre-commit Hook
Section titled “Pre-commit Hook”#!/bin/shscaf fmt --check || { echo "Run 'scaf fmt -w' to fix formatting" exit 1}Examples
Section titled “Examples”Format All Files
Section titled “Format All Files”# Dry runscaf fmt
# Apply changesscaf fmt -wCheck Before Commit
Section titled “Check Before Commit”# Check formattingif scaf fmt --check; then echo "Formatting OK"else echo "Run: scaf fmt -w" exit 1fiView Changes
Section titled “View Changes”# See what would changescaf fmt --diff queries/users.scaf