Code Style
Coding conventions of the core and how to apply them with clang-format and clang-tidy.
The core has a .clang-format and a .clang-tidy file in the root of its repository. Format your code with them before sending a change; this page sums up what they and the existing code expect.
Formatting
- Indentation with tabs, 4 columns wide.
- Lines up to 100 columns.
- Opening braces on the same line as the statement.
- The rest follows the Mozilla style that
.clang-formatis based on.
Naming
| What | Style | Example |
|---|---|---|
| Classes, structs, enums, functions, methods | PascalCase | ExtensionLoader, GetManager() |
| Interfaces | I + PascalCase | ILanguageModule, ILogger |
| Local variables, parameters, public fields | camelCase | baseDir, printReport |
| Private members | _camelCase | _impl, _data |
| Constants | k + PascalCase | kMaxFuncArgs |
| Enum values | PascalCase | ExtensionState::Running |
Headers and comments
#pragma oncein every header.- Public headers in
include/plugify/hide their implementation behind a pointer (struct Impl; std::unique_ptr<Impl> _impl;), so the layout of exported classes does not change when the implementation does. - Document public API with Doxygen comments:
/** @brief ... */before a declaration and///<after a field. - Errors are returned as
Result<T>(std::expected<T, std::string>), not thrown.
Tools
Format a file in place:
Run the static analysis on a file, using the compile commands of your build folder:
The CMake option PLUGIFY_USE_CLANG_TIDY=ON runs clang-tidy as part of the build. Most IDEs (Visual Studio, CLion, VS Code) pick up both files automatically.