docs/CODE_STYLE_GUIDE.md
Read the code, and follow the existing style as much as possible.
For C++, Java and Objective C/C++ code we use clang-format of version 22 or later.
brew install clang-formatpacman -S clangwget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
echo 'deb http://apt.llvm.org/noble/ llvm-toolchain-noble-22 main' | sudo tee /etc/apt/sources.list.d/ llvm-toolchain-noble-22.list
sudo apt-get update
sudo apt-get install -y clang-format-22 # Run it as clang-format-22
Make sure that clang-format is in your PATH.
.clang-formatgit commit hook (see below) for automatic formatting of changed filesclang-format -i file (clang-format-22 for Ubuntu)tools/unix/clang-format.shgit clang-formatgit clang-format HEAD~1clang-format binary.Install and setup the Clang-Format extension.
We are using swiftformat for Swift code. Install it and configure format on save in Xcode by following instructions at https://medium.com/@jozott/format-on-save-xcode-swift-8133d049b3ac
brew install swiftformatMake sure that swiftformat is in your PATH.
iphone/.swiftformatswiftformat <somefile.swift> to format a single filegit commit hook (see below) for automatic formatting of changed filesWe are using ktlint for Kotlin code formatting.
The canonical ktlint version is pinned in android/gradle/libs.versions.toml
(field ktlint). CI installs that exact version; please match it locally to
avoid formatting drift between your machine and the code-style-check-kotlin
job.
brew install ktlint (then verify ktlint --version matches the pinned version)Make sure that ktlint is in your PATH.
android/.editorconfigktlint --format <somefile.kt> to format a single filetools/unix/ktlint_format.shgit commit hook (see below) for automatic formatting of changed filesFollow the existing style in Python files as much as possible. We'll add a more detailed guide later.
Run git config core.hooksPath tools/hooks to set up the pre-commit hook.
After that, every time you commit, the hook will automatically format your
.java, .kt, .swift, .cpp, .hpp, .m, .mm, .h, and .cc code according to the project's style rules.
You can bypass the auto-formatting with git commit --no-verify if necessary.
To configure the formatting style, edit .clang-format, .swiftformat in the project root, and android/.editorconfig for Kotlin.
To configure which files are formatted, edit tools/hooks/format-config.bash
// TODO(DeveloperInitialsOrNickname): need to fix it comment