You've already forked xiaozhi-esp32
mirror of
https://github.com/m5stack/xiaozhi-esp32.git
synced 2026-05-20 11:35:10 -07:00
87f6faee79
- Added a comprehensive guide for creating custom boards in the XiaoZhi AI project, detailing directory structure, configuration files, and initialization code. - Introduced a new document explaining the MCP protocol for IoT control, including message formats and interaction flows. - Updated existing documentation to reflect changes in tool registration and usage examples for the MCP protocol. - Enhanced README files for better clarity and consistency across languages.
2.3 KiB
2.3 KiB
Code Style Guide
Formatting Tool
This project uses clang-format to keep the code style consistent. The .clang-format file in the project root is based on the Google C++ style guide with a few project-specific tweaks.
Installing clang-format
Make sure clang-format is available before you use it:
-
Windows:
winget install LLVM # or with Chocolatey choco install llvm -
Linux:
sudo apt install clang-format # Ubuntu/Debian sudo dnf install clang-tools-extra # Fedora -
macOS:
brew install clang-format
Usage
-
Format a single file:
clang-format -i path/to/your/file.cpp -
Format the entire project:
# Run from the project root find main -iname '*.h' -o -iname '*.cc' | xargs clang-format -i -
Check formatting without modifying files (useful in CI / pre-commit):
clang-format --dry-run -Werror path/to/your/file.cpp
IDE Integration
-
Visual Studio Code:
- Install the C/C++ extension.
- Set
C_Cpp.formattingtoclangFormatin settings. - Optionally enable
editor.formatOnSave.
-
CLion:
- Open
Editor > Code Style > C/C++in the settings. - Set
Formattertoclang-format. - Choose "use the .clang-format file in the project".
- Open
Main Rules
- Indent with 4 spaces.
- Line width capped at 100 characters.
- Attach-style braces (
{on the same line as the control statement). - Pointers and references bind to the type (left alignment).
- Includes are sorted automatically.
- Access specifiers are indented by -4 spaces.
Notes
- Make sure the code has been formatted before committing.
- Do not fix up alignment by hand after running clang-format.
- To exclude a block from formatting, wrap it with:
// clang-format off your code // clang-format on
FAQ
-
Formatting fails:
- Check whether
clang-formatis too old. - Make sure the file is UTF-8 encoded.
- Validate the syntax of your
.clang-formatfile.
- Check whether
-
Output differs from what you expected:
- Verify that the
.clang-formatin the project root is actually picked up. - Make sure no other
.clang-formathigher in the tree is winning.
- Verify that the
Questions and suggestions are welcome - please open an issue or a pull request.