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-format is based on.
namespace plugify {
    class Example {
    public:
        Result<void> Run(std::string_view name) {
            if (name.empty()) {
                return MakeError("Name is empty");
            }
            return {};
        }
    };
}

Naming

WhatStyleExample
Classes, structs, enums, functions, methodsPascalCaseExtensionLoader, GetManager()
InterfacesI + PascalCaseILanguageModule, ILogger
Local variables, parameters, public fieldscamelCasebaseDir, printReport
Private members_camelCase_impl, _data
Constantsk + PascalCasekMaxFuncArgs
Enum valuesPascalCaseExtensionState::Running

Headers and comments

  • #pragma once in 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:

clang-format -i src/core/manager.cpp

Run the static analysis on a file, using the compile commands of your build folder:

clang-tidy -p build src/core/manager.cpp

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.