← Back to Skills Marketplace
daxiali

C++/CPP Code Style

by daxiali · GitHub ↗ · v1.0.0 · MIT-0
linuxdarwinwin32 ⚠ suspicious
132
Downloads
0
Stars
0
Active Installs
1
Versions
Install in OpenClaw
/install cpp-code-style
Description
C++/CPP代码都用这个coding style, code style, 代码风格,写代码之前阅读下面规则
README (SKILL.md)

Google C++ Style Guide

写代码严格按照下面规则。 注意:external,3rdparty,.gitignore里面的文件都不在该规则范围内。

关键规则

1. 命名规范

  • 文件名: snake_case.hpp, snake_case.cpp
  • 类名: CamelCase
  • 函数名: camelCase(小驼峰,首字母小写)
  • 变量名: snake_case
  • 类成员变量: m_camelCase(m_前缀 + 小驼峰),不要m_camelCase_
  • 常量: kCamelCase(全局常量用 g_CamelCase
  • 命名空间: snake_case

2. 缩进和格式

  • 缩进: 2 个空格,不使用 Tab
  • 行宽: 80 字符(软限制)
  • 大括号: 函数和类的开始大括号在新行,控制流语句的大括号在同一行
  • 行尾空格: 去掉行尾空格
class Foo : public Bar {
 public:
  void Method() {
    if (condition) {
      DoSomething();
    }
  }
};

3. 空格

  • 二元和三元操作符周围有空格
  • 函数参数列表的第一个左括号紧贴函数名
  • 返回类型和函数名之间有一个空格
  • 指针/引用符号贴在类型上,而不是变量名
// 正确
int* ptr;
int& ref;
void Func(int param1, int param2) { ... }

// 类成员变量
class MyClass {
 public:
  void myMethod() {
    m_counter = 0;  // m_ 前缀
    int local_var = 0;  // 局部变量用 snake_case
  }

 private:
  int m_counter;  // 成员变量 m_ + camelCase
};

// 错误
int *ptr;
int &ref;
void Func( int param1, int param2 ) { ... }
class MyClass {
  int counter;  // 缺少 m_ 前缀
};

4. 头文件保护

#pragma once
// 或者
#ifndef _FILE_NAME_H_
#define _FILE_NAME_H_

// ... code ...

#endif  // _FILE_NAME_H_

5. 命名空间

  • 不使用 using namespace 污染全局命名空间
  • 使用 namespace foo {} // namespace foo 的格式
  • 文件作用域的 namespace 声明后跟一对空大括号
namespace litho {
namespace geo {

class Point { ... };

}  // namespace geo
}  // namespace litho

6. 注释

  • 使用英文注释
  • 使用 // 单行注释
  • 使用 /* */ 多行注释(仅当需要块注释时)
  • 函数和类的文档使用 /** ... */ 格式
// 单行注释

/*
 * 多行注释
 */

/**
 * 函数描述
 * @param x 参数描述
 * @return 返回值描述
 */

7. 其他重要规则

  • 私有成员: 在 private: 之前声明公有的
  • 内联函数: 定义在头文件中
  • 虚拟函数: 声明为 virtual,在定义中不使用 virtual 关键字
  • 常量成员: 使用 constexpr 而不是 const
  • 字符串字面量: 使用 // NOLINT 关闭特定的 lint 警告(如果需要)
  • CMakefile:不要用绝对路径和中文注释
  • CopyRight: 使用当前年份,如2026
  • template: template在class和function上一行
  • 类成员变量: 需要初始化
  • include顺序:标准库 → 第三方库 → 项目头文件

工具

clang-format

项目已配置 .clang-format 文件,使用 Google 风格。 检查.clang-format 文件是否符合上述规则,不符合修改.clang-format 文件。

格式化文件:

clang-format -i src/geo/*.hpp tests/*.cpp

参考

Usage Guidance
This skill is primarily a local C++ style guide and formatter helper and appears safe in intent, but take these precautions before using it: - Confirm tooling: The instructions call for clang-format, but the skill metadata lists g++/gcc instead. Make sure clang-format is installed and available (and that g++/gcc are actually needed) before running any automated formatting. - Expect file changes: The skill tells the agent to modify .clang-format and run clang-format -i on source files. Run it on a branch or a copy, or commit your work first so you can review changes. - Verify file paths and scope: The example formatting command targets specific paths (src/geo/*.hpp tests/*.cpp). Ensure the paths match your project or adjust them; automatic recursive edits can touch many files if misconfigured. - Trust and provenance: The skill has no homepage and an unknown source; if the style rules or automatic edits are important for your project, prefer an internally-reviewed .clang-format and trusted tooling. If you want to proceed: install and verify clang-format, test the formatting commands on a small sample, and run in a safe/isolated branch so you can inspect changes before merging.
Capability Analysis
Type: OpenClaw Skill Name: cpp-code-style Version: 1.0.0 The skill bundle provides standard C++ coding style guidelines based on the Google C++ Style Guide. The instructions in SKILL.md are focused on naming conventions, formatting, and the use of clang-format, with no evidence of malicious intent, data exfiltration, or unauthorized execution.
Capability Assessment
Purpose & Capability
The skill's stated purpose is a C++ code style guide and formatter. The SKILL.md refers to running clang-format and editing .clang-format, but the skill metadata requires g++ and gcc. Requiring compilers (g++, gcc) is unnecessary for a style guide/formatter and does not match the actions described; conversely, clang-format (which is needed) is not listed as a required binary.
Instruction Scope
The instructions are focused on style rules and explicitly tell the agent to check and modify the project's .clang-format and to run clang-format on source files (e.g., clang-format -i src/geo/*.hpp tests/*.cpp). This is within the scope of a style/formatting skill, but it does instruct the agent to modify repository files — users should expect automatic source edits.
Install Mechanism
No install spec or code files are present; this is an instruction-only skill. No downloads or installs are requested, so there is low install risk.
Credentials
The skill declares no required environment variables, credentials, or config paths. That is appropriate for a style guide/formatter helper.
Persistence & Privilege
The skill is not always-enabled and can be invoked by the user. It does not request persistent privileges or modify other skills or global agent settings.
How to Use
  1. Make sure OpenClaw is installed (local or Docker)
  2. Run the install command in chat: /install cpp-code-style
  3. After installation, invoke the skill by name or use /cpp-code-style
  4. Provide required inputs per the skill's parameter spec and get structured output
Version History
v1.0.0
- Initial release of the C++/CPP Code Style skill. - Provides a comprehensive C++ code style guide based on the Google C++ Style Guide. - Covers naming conventions, indentation, bracket placement, whitespace, header guards, namespaces, and commenting standards. - Includes rules for include order, member variable initialization, and CMakefile practices. - Recommends use of a project `.clang-format` file in Google style and lists formatting commands.
Metadata
Slug cpp-code-style
Version 1.0.0
License MIT-0
All-time Installs 0
Active Installs 0
Total Versions 1
Frequently Asked Questions

What is C++/CPP Code Style?

C++/CPP代码都用这个coding style, code style, 代码风格,写代码之前阅读下面规则. It is an AI Agent Skill for Claude Code / OpenClaw, with 132 downloads so far.

How do I install C++/CPP Code Style?

Run "/install cpp-code-style" in the OpenClaw or Claude Code chat to install it in one step — no extra setup required.

Is C++/CPP Code Style free?

Yes, C++/CPP Code Style is completely free, licensed under MIT-0. You can download, install and use it at no cost.

Which platforms does C++/CPP Code Style support?

C++/CPP Code Style is cross-platform and runs anywhere OpenClaw / Claude Code is available (linux, darwin, win32).

Who created C++/CPP Code Style?

It is built and maintained by daxiali (@daxiali); the current version is v1.0.0.

💬 Comments