跳到正文
cccskills
免费在 GitHub 公开中文介绍

Code style

了解 Carbon 工具链对 Bazel、C++、Carbon、Markdown 和 Python 文件的格式规范,并查看注释、文档、命名、设计及提交说明的写作要求。

原文查看原文说明

Instructions for code formatting and style guidelines in the Carbon toolchain.

carbon-language/carbon-lang星标 33,929(GitHub 33,929 + cccskills 0)

实测评分 未实测

查看安装方法

适用场景

  • 整理 Carbon 代码格式
  • 检查注释和文档
  • 确认名称是否符合实际含义
  • 撰写准确描述改动的提交说明

中文介绍

功能

本技能介绍 Carbon 工具链代码和文档的编写规范。它列出了 Bazel、C++、Markdown 和 Python 文件各自使用的格式化工具与检查方法。由于 Carbon 的 format 命令目前效果不理想,建议参考已有的 Carbon 代码和 C++ 风格。内容还包括:注释应说明现有代码的行为或原因,文档说明应先给出直接概述,名称应符合实际职责或含义。技能也涉及让文档与代码修改保持一致、不要为了改善打印结果而扭曲数据模型,以及在提交说明中具体描述改动成果。

适用场景

编写或修改 Carbon 工具链代码时,可以使用本技能。需要检查注释、名称、文档或提交说明是否符合项目规范时也适用。

使用示例

  • “这个 C++ 文件应该使用哪种格式化工具?”
  • “检查这条注释和变量名是否符合规范。”
  • “请改写这段提交说明,让改动内容更清楚。”

注意事项

不同文件类型使用的工具和规范不同:C++ 参考 Carbon C++ Project Style Guide,Markdown 参考 Google developer documentation style guide,Python 参考 PEP 8。资料指出 Carbon 的 format 命令目前运行效果不佳。

本介绍由 AI(OpenAI Codex)根据公开的 SKILL.md 撰写。准确的规格请查看下方原文。

文档检查

AI 根据 SKILL.md 的内容检查了需要注意的操作和使用前提。评分只依据实际运行的结果(实测对比)。

安全性发送数据、删除文件、执行命令等是否有说明
A良好内容主要是格式整理和检查,不涉及外部发送或删除操作。
安装难易度所需工具和 API 密钥是否少且有说明
B部分不足需要使用 `pre-commit` 和格式化工具,但未提供安装步骤。

不计入评分。 由 AI(OpenAI Codex)于 2026年10月26日 评估。仅供参考,安装前请同时查看原文。

如果您认为评估有误,请申请复核

请写明哪一项有误以及原因。无需登录。我们会对照 SKILL.md 重新评估,并在此处更新结果。

此表单受 reCAPTCHA 保护,适用 Google 的隐私权政策和服务条款。

包含的文件(1)

  • SKILL.md6.0 KB

SKILL.md(原文)

安装前可以查看交给 AI 代理的指令内容。

Code style

<!-- Part of the Carbon Language project, under the Apache License v2.0 with LLVM Exceptions. See /LICENSE for license information. SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -->

License

Formatting

  • Bazel: Use pre-commit run buildifier --files <file.bzl> to format Bazel files.
  • C++: Use pre-commit run clang-format --files <file.cpp> to format C++ files.
  • Carbon: The toolchain's format command doesn't work well right now. Instead, try to format Carbon code based on other Carbon files and the C++ style.
  • Markdown: Use pre-commit run prettier --files <file.md> to format markdown files.
  • Python: Use pre-commit run black --files <file.py> to format Python files.

Comments

  • Describe the code that is there. A comment should explain what the current code does or why it is the way it is, not narrate what the code used to be. Do not add a comment to justify a deletion or explain that something is no longer necessary; a reader of the new code has no idea what is being contrasted against, and the comment rots as soon as the old shape is forgotten. Put that reasoning in the commit message instead.
  • Do not introduce a local variable just to host a comment. If a call argument reads clearly on its own, inline it rather than naming it so that a comment has somewhere to attach.
  • Lead with a plain summary. Start a doc comment with a direct statement of what the function does or returns, such as "Returns true if the InstKind is a singleton." Put nuance in a following sentence rather than qualifying the summary into something harder to read.
  • Re-read a comment before updating it. When a symbol is renamed or changes meaning, a comment that mentions it is not automatically stale. Work out what the comment actually asserts first: it may be describing what the code uses, which is still true, and rewriting it loses information.

Documentation

This covers standalone prose: /docs, README.md files, and the skill files under .agents/skills.

  • Be true of the tree it lands in. Documentation shipping in the same commit as the code it describes should name that code freely. Documentation that lands separately must not: a reader who greps for an identifier from an unlanded change finds nothing, and a claim that only holds after that change is false until it lands. This is easy to get wrong when writing up a lesson while the change that taught it is still in flight.
  • Use placeholders for illustrations. When an example only needs to show a shape, name it Foo rather than reaching for a real symbol. Save real identifiers for documenting that identifier, where going stale is at least detectable.
  • Make each point stand alone. A reader has none of the discussion that produced it. State the rule, and enough of the reason to apply it, without assuming knowledge of the change that motivated it.

Naming

  • A name is a claim, so keep it true. When a change invalidates the invariant a name describes, rename it in the same change. A factory called MakeSingletonFooId has to be renamed once Foo is no longer a singleton, even though nothing forces you to.
  • Types in a signature are part of the claim. A function returning the id of a namespace should return InstId, not TypeInstId, because a namespace is not a type. Do not let a convenient wider or narrower id type imply something false.
  • Delete a predicate whose name stops distinguishing anything. If a change widens a test so that it no longer says what its name implies, remove it and let callers use the underlying test, rather than keeping a wrapper that sounds meaningful. What callers actually want is often the inverse, and is worth adding under its own name.
  • Name a variable for its role, not its representation. If the role a value plays is unchanged, keep its name even when a change means it is now held or spelled differently.

Commit descriptions

  • Say what the change is, not how you made it. Describe the resulting code. Only describe process when the process is more interesting than the change, as with a large mechanical transformation.
  • Do not narrate your own work. Statements like "each such site was audited" or "we investigated every caller" describe effort, not the change.
  • Omit routine mechanical steps. Do not mention running the testdata autoupdater or the formatter. Every change is expected to include those.
  • Do not enumerate each edit. Describe the change as a whole rather than listing every function or file touched; the diff already lists them.
  • Use the project's terms precisely. Reach for the term of art the codebase uses. Calling something a "type alias" or a "namespace" when it is a named scope misleads, and is worse than a vaguer but accurate word.
  • Scope claims to what changed. Say the specific thing that is now true, rather than a broader statement that happens to contain it.

Design

  • Do not distort the data model to improve output. If printed or golden output is undesirable, change the printer, not the data structures that feed it.

Style Guides

评价

还没有评价。欢迎分享你的使用感受。

评论

无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。

还没有评论。来写第一条吧。

提交后会立即公开。请勿填写邮箱、电话等个人信息。URL 最多 2 个。

0 / 1000 字

此表单受 reCAPTCHA 保护,适用 Google 的隐私权政策和服务条款。

同一仓库的技能

本技能介绍如何使用命令行`gh`只读查看GitHub issue正文和评论,支持通过编号或URL定位,也可指定其他仓库,并说明如何提取大量评论。

  • 查看issue正文和评论
  • 通过URL读取issue
  • 查看其他仓库的issue
carbon-language/carbon-lang3.4万2026年10月26日 更新

Agent tools

免费有简介

本技能为在 Carbon 代码库中工作的 AI 助手规定文件查看、搜索和编辑工具,并说明临时文件的存放与清理规则,以及何时可以编写和运行自定义程序。

  • 按规定工具搜索Carbon文件
  • 为文件编辑选择专用工具
  • 确认临时文件的存放与清理规则
carbon-language/carbon-lang3.4万2026年10月26日 更新

Bazel usage

免费有简介

了解如何在 Carbon 项目中通过 Bazelisk 构建、测试和运行程序,包括指定目标、启用 ASan,以及系统依赖变更后重建缓存。

  • 构建 Carbon 代码
  • 运行与修改相关的测试
  • 启动 Bazel 构建的程序
carbon-language/carbon-lang3.4万2026年10月26日 更新

Builtin functions

免费有简介

本技能介绍如何为Carbon编译器添加内置函数,包括类型注册、签名验证、常量求值、运行时LLVM IR生成、Prelude绑定,以及使用最小Prelude编写针对性测试。

  • 注册内置函数
  • 实现常量求值
  • 添加LLVM IR生成
carbon-language/carbon-lang3.4万2026年10月26日 更新

Diagnostics

免费有简介

本技能介绍如何在Carbon工具链中添加或修改错误和警告,包括注册诊断类型、用带类型的参数构造消息、为源码位置添加标签和上下文,以及检查措辞规范和测试覆盖。

  • 添加诊断消息
  • 为源码位置添加标签
  • 统一诊断措辞
carbon-language/carbon-lang3.4万2026年10月26日 更新

GitHub CLI usage

免费有简介

使用 `gh` 只读搜索和查看 GitHub 的议题、拉取请求、仓库与代码,并了解如何查询 REST 和 GraphQL API、翻页获取结果及筛选或整理输出。

  • 查看议题内容和状态
  • 检查拉取请求差异与检查状态
  • 搜索 GitHub 代码或仓库
carbon-language/carbon-lang3.4万2026年10月26日 更新

查看 carbon-language 的全部技能

报告此技能的问题