Skip to main content
Automatically format Leo source files according to the official Leo style guide. This command ensures consistent code formatting across your project.

Usage

Options

boolean
Check if files are formatted without making changes. Exit with code 1 if any files need formatting.
string
Specific file or directory to format. Defaults to current directory.

Examples

Format all files in project

Check formatting without changes

This is useful in CI/CD pipelines:

Format specific file

Format specific directory

Formatting Rules

Leo follows these formatting conventions:

Indentation

  • Use 4 spaces for indentation
  • No tabs

Line Length

  • Maximum 120 characters per line
  • Break long lines at logical points

Spacing

Function Declarations

Imports

Integration

Pre-commit Hook

Add to .git/hooks/pre-commit:

VS Code

Configure VS Code to format on save by adding to .vscode/settings.json:

CI/CD Integration

Add formatting check to your CI pipeline:
  • Build - Compile your formatted code
  • Test - Run tests on formatted code

Best Practices

Run leo fmt before committing code to maintain consistent style across the team.
The formatter preserves comments and applies minimal changes to maintain code readability.

Troubleshooting

Format check fails in CI

If leo fmt --check fails in CI, run locally:

Syntax errors prevent formatting

Fix syntax errors before formatting: