Formatter
The Tova formatter (tova fmt) automatically formats .tova source files for consistent code style across your project.
Usage
Format one or more files:
tova fmt src/app.tova
tova fmt src/app.tova src/utils.tova src/models.tovaCheck Mode
Use --check to verify formatting without modifying files. This is useful in CI pipelines:
tova fmt src/app.tova --checkIf the file is already formatted, you will see:
Already formatted: src/app.tovaIf the file needs formatting, you will see:
Would reformat: src/app.tovaIn check mode, the command exits with code 1 if any files need formatting, making it easy to integrate into CI:
# In CI pipeline
tova fmt src/*.tova --check || (echo "Run 'tova fmt' to fix formatting" && exit 1)What It Formats
The formatter parses the source file into an AST and re-prints it with consistent style. This normalizes:
- Indentation -- Consistent indentation levels using spaces
- Spacing -- Uniform spacing around operators, after commas, and around braces
- Line breaks -- Consistent placement of opening and closing braces
- Trailing commas -- Normalized comma placement in lists and parameters
- Block structure -- Consistent formatting of
shared,server, andbrowserblocks
Example
Before formatting:
server{
fn get_users( ) {
users=db.query("SELECT * FROM users")
users |>map( fn(u) u.name )
}
route GET "/api/users"=> get_users
}After tova fmt:
server {
fn get_users() {
users = db.query("SELECT * FROM users")
users |> map(fn(u) u.name)
}
route GET "/api/users" => get_users
}Editor Integration
When using the VS Code extension, the formatter is available through the LSP as document formatting. You can format on save or on demand with the standard VS Code formatting shortcut (Shift+Alt+F on Windows/Linux, Shift+Option+F on macOS).