coding-standards

A set of general coding standards for naming, function design, variables, constants, and separating responsibilities across programming languages.

In plain words
What is it for?
Use it when writing or reviewing code to choose clear names, design focused functions, define variables consistently, and avoid mixing unrelated work.
Why use it?
It helps keep code readable and consistent, making its purpose easier to understand and maintain.

Cursor rule for Cursor

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/mywand/cusrsor-do-it/coding-standards
Clone the repo
git clone --depth 1 https://github.com/mywand/cusrsor-do-it

Made for: Cursor.

Per session 2,803 This file is loaded in full into every session.
When invoked 2,803 The same file — it is already loaded in full.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.02803 $0.02803
Opus 5 $0.01401 $0.01401
Sonnet 5 $0.00561 $0.00561
Haiku 4.5 $0.00280 $0.00280

Measured 2d ago against content hash e5ded84b7771, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

coding-standards scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.cursor/rules/tools/coding-standards.mdc · 428 lines

How it starts

The opening of the file, as written. The whole thing — 428 lines — stays where its author put it; the contents beside it link to each section on GitHub.

最近更新: 2025-10-10

跨语言通用编码规范

适用于所有编程语言的通用编码标准和最佳实践

1. 命名规范

1.1 通用原则

  • 有意义: 名称应该清楚表达意图
  • 可读性: 避免缩写和单字母变量(除了循环计数器)
  • 一致性: 在同一项目中保持命名风格一致
  • 避免误导: 不使用容易混淆的名称
// ❌ 不好的命名
let d = new Date()
let u = users.filter(x => x.a)
function calc(a, b) { return a * b * 0.1 }

// ✅ 好的命名
let currentDate = new Date()
let activeUsers = users.filter(user => user.isActive)
function calculateDiscount(price, quantity) { return price * quantity * 0.1 }

1.2 函数命名

  • 使用动词开头,清楚表达函数的作用
  • 布尔函数使用 ishascanshould 等前缀
# ✅ 好的函数命名
def get_user_by_id(user_id):
def create_new_order(order_data):
def is_valid_email(email):
def has_permission(user, resource):
def can_access_resource(user, resource):

1.3 变量命名

  • 使用名词或名词短语
  • 集合使用复数形式
  • 常量使用全大写(根据语言习惯)
// ✅ 好的变量命名
String userName;
List<User> activeUsers;
final int MAX_RETRY_COUNT = 3;
boolean isProcessing;

2. 函数设计

2.1 单一职责原则

每个函数应该只做一件事,并且把它做好。

// ❌ 职责过多
function processUserData(userData: any) {
  // 验证数据
  if (!userData.email) throw new Error('邮箱必填')
  
  // 保存到数据库
  database.save(userData)
  
  // 发送邮件
  emailService.send(userData.email, 'welcome')
  
  // 记录日志
  logger.info('用户创建成功')
}

// ✅ 职责分离
function validateUserData(userData: UserData): void {
  if (!userData.email) throw new Error('邮箱必填')
}

function saveUser(userData: UserData): User {
  return database.save(userData)
}

function sendWelcomeEmail(email: string): void {
  emailService.send(email, 'welcome')
}

function createUser(userData: UserData): User {
  validateUserData(userData)
  const user = saveUser(userData)
  sendWelcomeEmail(userData.email)
  logger.info('用户创建成功', { userId: user.id })
  return user
}

2.2 参数控制

  • 函数参数不超过 3-4 个
  • 使用对象传递多个参数
  • 提供合理的默认值
# ❌ 参数过多
def create_user(name, email, age, phone, address, city, country, postal_code):
    pass

# ✅ 使用对象封装
def create_user(user_data: UserData):
    pass

# 或使用字典(Python)
def create_user(name: str, email: str, **kwargs):
    age = kwargs.get('age', 18)
    phone = kwargs.get('phone', '')
    # ...

Read the full file on GitHub · 428 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 428 lines · 2,803 tokens per session scan A e5ded84b7771

Subscribe to this mod's changes

coding-standards is a cursor rule published in the GitHub repository mywand/cusrsor-do-it (2 stars, last pushed 7mo ago), licensed Apache-2.0. It adds 2,803 tokens to every session, about $0.0140 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.