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.
- macOS:
brew install clang-format - Windows (MSYS2):
pacman -S clang - Ubuntu 24:
wget -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.
- Configuration is in
.clang-format - Set up a
git commithook (see below) for automatic formatting of changed files - To manually format a file run
clang-format -i file(clang-format-22for Ubuntu) - To format all files in the repository run
tools/unix/clang-format.sh - To format changes added to commit run
git clang-format - To format already committed changes run
git clang-format HEAD~1
- Install this plugin: https://plugins.jetbrains.com/plugin/20785-clang-format-tools
- Then go to Preferences -> Other Settings -> ClangFormat and set the path to your installed
clang-formatbinary. - Enable "Reformat code on file save" option.
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
- macOS:
brew install swiftformat
Make sure that swiftformat is in your PATH.
- Configuration is in
iphone/.swiftformat - Run
swiftformat <somefile.swift>to format a single file - Set up a
git commithook (see below) for automatic formatting of changed files
We 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.
- macOS:
brew install ktlint(then verifyktlint --versionmatches the pinned version) - Other platforms: download the pinned version from GitHub Releases
Make sure that ktlint is in your PATH.
- Configuration is in
android/.editorconfig - Run
ktlint --format <somefile.kt>to format a single file - To format all Kotlin files in the repository run
tools/unix/ktlint_format.sh - Set up a
git commithook (see below) for automatic formatting of changed files
We use detekt for Kotlin static analysis: naming conventions, complexity, code smells, and potential bugs.
The canonical detekt version is pinned in android/gradle/libs.versions.toml
(field detekt). CI installs that exact version; please match it locally.
- Download the matching version from GitHub Releases (
detekt-cli-<version>-all.jar) - Or run via Gradle (no local install needed):
cd android && ./gradlew :app:detektCheck
- Configuration is in
android/detekt.yml - Run
cd android && ./gradlew :app:detektCheckto check theappmodule - Run
cd android && ./gradlew detektCheckto check all Kotlin-enabled modules
- Hungarian notation (
mprefix) is forbidden for private properties: use_camelCasefor backing fields,camelCasefor regular properties - Formatting rules are handled by ktlint, not detekt (no overlap)
Follow 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
- Check the existing code base for examples of how to do things, and to reuse existing utilities and functions
- Write the code without warnings
- If you see outdated code which can be improved, DO IT NOW (but in a separate pull request or commit)!
- Your code should work at least on [mac|linux|android][x86|x86_64], [ios|android][x86|armv7|arm64] architectures
- Your C++ code should compile with C++23 compiler
- Avoid using any new 3party library if it is not fully tested and supported on all our platforms
- Cover your code with unit tests. See examples for existing libraries
- Ask if you have any questions
- If you don't have enough time to make it right, or see a potential issue, leave a
// TODO(DeveloperInitialsOrNickname): need to fix itcomment