coding-standards

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Coding Standards

编码标准

You enforce coding standards by detecting the project language and applying the correct style guide.
你需要通过检测项目语言并应用正确的风格指南来强制执行编码标准。

Step 1 — Detect the language

步骤1 — 检测语言

Look at the file extensions, project config files, and context of the user's request to determine the primary language.
查看文件扩展名、项目配置文件以及用户请求的上下文,以确定主要语言。

Step 2 — Fetch the right guide

步骤2 — 获取对应的指南

Based on the detected language, fetch and read the corresponding style guide using
WebFetch
:
LanguageGuideURL
PythonGoogle Python Style Guide
https://raw.githubusercontent.com/google/styleguide/refs/heads/gh-pages/pyguide.md
TypeScriptAnthony Fu's ESLint Config
https://eslint-config.antfu.me/rules
GoUber Go Style Guide
https://raw.githubusercontent.com/uber-go/guide/refs/heads/master/style.md
RustRust API Guidelines
https://rust-lang.github.io/api-guidelines/print.html
C / C++LLVM Coding Standards
https://llvm.org/docs/CodingStandards.html
JavaScriptAirbnb JavaScript Style Guide
https://raw.githubusercontent.com/airbnb/javascript/refs/heads/master/README.md
根据检测到的语言,使用
WebFetch
获取并阅读相应的风格指南:
语言指南链接
PythonGoogle Python风格指南
https://raw.githubusercontent.com/google/styleguide/refs/heads/gh-pages/pyguide.md
TypeScriptAnthony Fu的ESLint配置
https://eslint-config.antfu.me/rules
GoUber Go风格指南
https://raw.githubusercontent.com/uber-go/guide/refs/heads/master/style.md
RustRust API指南
https://rust-lang.github.io/api-guidelines/print.html
C / C++LLVM编码标准
https://llvm.org/docs/CodingStandards.html
JavaScriptAirbnb JavaScript风格指南
https://raw.githubusercontent.com/airbnb/javascript/refs/heads/master/README.md

Step 3 — Satisfy the user's request

步骤3 — 满足用户的请求

Use the fetched guide as your reference to do what the user asked — whether that's reviewing code, fixing style issues, refactoring, or writing new code that follows the standard.
Always cite the specific rule or section from the guide when making suggestions.
以获取到的指南为参考,完成用户的请求——无论是代码审查、修复风格问题、重构还是编写符合标准的新代码。
提出建议时,请务必引用指南中的具体规则或章节。

Commit messages

提交信息

When writing commit messages, follow Conventional Commits:
Commit messages must be:
  • Single line — header only, no body unless absolutely necessary
  • Short — 72 character max (
    header-max-length
    )
  • Minimal — state what changed, nothing more
  • Conventional
    type(scope): subject
    format (e.g.
    fix(api): handle null response
    )
Good:
feat(auth): add jwt refresh
| Bad:
Added a new feature that refreshes the JWT token when it expires
编写提交信息时,请遵循Conventional Commits规范:
提交信息必须:
  • 单行 — 仅包含标题,除非绝对必要,否则不要添加正文
  • 简短 — 最多72个字符(
    header-max-length
  • 简洁 — 说明变更内容即可,无需多余信息
  • 符合规范
    type(scope): subject
    格式(例如:
    fix(api): handle null response
良好:
feat(auth): add jwt refresh
| 糟糕:
Added a new feature that refreshes the JWT token when it expires