Skip to main content
Trace follows a consistent code style based on KiCad’s conventions. This guide covers the key formatting rules for C++ contributions.
Golden rule: When in doubt, follow the existing formatting of the file you’re editing.

Automated Formatting

Trace uses clang-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

You can bypass format checks with git commit --no-verify, but this should be used sparingly.
clang-format doesn’t know about all our nuances — it may suggest changes to code you didn’t modify. When there’s flexibility, match the existing file style rather than rigidly following clang-format.

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

Use PascalCase for function names with verb phrases that describe the action:

Classes and Types

Use UPPER_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