Golden rule: When in doubt, follow the existing formatting of the file you’re editing.
Automated Formatting
Trace usesclang-format for automated code formatting. The repository includes a _clang-format configuration file that defines our style rules.
Setting Up Git Hooks
Enable the formatting hooks to check your code before committing:Checking and Fixing Format
git commit --no-verify, but this should be used sparingly.
Indentation & Spacing
Indentation
- Use 4 spaces for indentation (no tabs)
- Continuation lines use 8 spaces
- Constructor initializer lists use 8 spaces
Spaces in Parentheses
Add spaces inside parentheses:No Space Before Parentheses
Space After Casts
Braces
Allman Style
Braces go on their own line:Always Use Braces
Even for single statements:Short Case Labels
Short case labels can be on a single line:Line Length
Maximum line length is 120 characters. Break long lines at logical points:Naming Conventions
Variables
Functions and Methods
UsePascalCase for function names with verb phrases that describe the action:
Classes and Types
UseUPPER_SNAKE_CASE for class names, enums, and enum values:
Pointers and References
Pointer and reference symbols attach to the type, not the variable:Comments
Single-Line
Multi-Line
Doxygen Documentation
Use Doxygen-style comments for public APIs:Includes
Don’t sort includes automatically — the existing order in files is intentional. Group includes logically:Constructors
Constructor initializer lists break after the colon:Lambdas
clang-format doesn’t fully support our lambda style. Follow existing patterns:
Quick Reference
Additional Resources
- KiCad Code Style Policy — Trace is based on KiCad’s conventions
- Contributing Guide — General contribution guidelines

