Skip to content

scaf fmt

The fmt command formats scaf files to a consistent style.

Terminal window
# Format all .scaf files in current directory
scaf fmt
# Format specific file
scaf fmt queries/users.scaf
# Format files in a directory
scaf fmt ./queries/

Write changes back to files (default: false):

Terminal window
# Preview changes (dry run)
scaf fmt queries/users.scaf
# Apply changes
scaf fmt --write queries/users.scaf
scaf fmt -w queries/users.scaf

Exit with error if files need formatting (useful for CI):

Terminal window
scaf fmt --check

Returns exit code 1 if any files would change.

Show diff of changes:

Terminal window
scaf fmt --diff queries/users.scaf

Two spaces for all indentation:

GetUser {
group "tests" {
test "example" {
$userId: 1
u.name: "Alice"
}
}
}
  • 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 are formatted as-is (preserving your SQL/Cypher formatting):

fn GetUser `
MATCH (u:User {id: $userId})
RETURN u.name, u.email, u.age
`

Comments are preserved and aligned:

// This is a top-level comment
fn GetUser `...`
GetUser {
// Group comment
group "tests" {
test "example" {
$userId: 1 // Inline comment
u.name: "Alice"
}
}
}

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
}
- name: Check formatting
run: scaf fmt --check
#!/bin/sh
scaf fmt --check || {
echo "Run 'scaf fmt -w' to fix formatting"
exit 1
}
Terminal window
# Dry run
scaf fmt
# Apply changes
scaf fmt -w
Terminal window
# Check formatting
if scaf fmt --check; then
echo "Formatting OK"
else
echo "Run: scaf fmt -w"
exit 1
fi
Terminal window
# See what would change
scaf fmt --diff queries/users.scaf