用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/xenoterracide/agent-skills --skill coding-standards命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
正在显示 SKILL.md
基于 SOC 职业分类
| name | coding-standards |
| description | Use when writing or modifying code in any language. |
| license | CC-BY-NC-SA-4.0 |
| metadata | {"copyright":"Caleb Cushing"} |
These standards apply to all programming tasks regardless of language or framework.
Design code that follows SOLID principles with a focus on polymorphic behavior:
Encapsulate behavior so it's polymorphic - let the unit decide how to act rather than orchestrating externally.
Polymorphism takes many forms:
// BAD - external orchestration with conditionals
public void processPayment(PaymentType type, Amount amount) {
if (type == PaymentType.CREDIT_CARD) {
processCreditCard(amount);
} else if (type == PaymentType.PAYPAL) {
processPayPal(amount);
} else if (type == PaymentType.BANK_TRANSFER) {
processBankTransfer(amount);
}
}
// GOOD - polymorphic behavior, each type decides how to act
public interface PaymentMethod {
void pay(Amount amount);
}
public class CreditCardPayment implements PaymentMethod {
@Override
public void pay(Amount amount) {
// Credit card specific implementation
}
}
// Usage - no conditionals, behavior is encapsulated
public void processPayment(PaymentMethod method, Amount amount) {
method.pay(amount); // Polymorphic dispatch
}
If you follow these principles, your code will naturally be composable, clear, and aligned with the domain.
Prefer immutable objects and data structures where immutability doesn't reduce comprehension.
Benefits:
Examples:
// GOOD - immutable record
public record Person(String name, int age) {}
// GOOD - immutable collections
var items = List.of("a", "b", "c"); // Cannot be modified
// GOOD - builder pattern for complex immutables
var config = Config.builder().timeout(Duration.ofSeconds(30)).retries(3).build();
Avoid setters - Instead of anemic data objects with getters/setters, prefer domain-driven design with rich behavior:
// BAD - anemic object with setter
person.setStatus("APPROVED");
// GOOD - tell, don't ask
person.approve();
When mutability is acceptable:
Errors must never be silently ignored. Always handle errors explicitly by either:
Empty catch blocks:
// BAD - exception is silently lost
try {
riskyOperation();
} catch (Exception e) {
// ignored
}
Rethrow when you cannot handle it:
// GOOD - rethrow to let caller handle
try {
riskyOperation();
} catch (IOException e) {
throw new ApplicationException("Failed to process file", e);
}
Log when you need to continue:
// GOOD - log with context before continuing
try {
optionalCleanup();
} catch (Exception e) {
log.warn("Cleanup failed for resource {}, continuing anyway", resourceId, e);
}
Can you recover from this error?
Should the caller know about this error?
Is this an optional/non-critical operation?
Before implementing new functionality, check if it's already provided by standard libraries or existing dependencies. Prefer existing code over writing your own, even for seemingly "trivial" functions.
Before considering any task complete, run the relevant tests. See the testing
skill for test philosophy, patterns, and anti-patterns.
Tools like Checkstyle, SpotBugs, Error Prone, and others exist to catch issues early.
The Rule:
| Issue Found | Action |
|---|---|
| Violation reported | Fix it - don't suppress blindly |
| Fix would make code worse | Suppress at the source with justification |
Suppress static analysis warnings only when:
Suppress at the closest point to the issue:
// GOOD - suppression is right at the source, with explanation
@SuppressWarnings("NullAway") // Factory method ensures non-null via validation
public static User create(String email) {
// ... validation logic ...
return new User(email); // NullAway can't see validation
}
// BAD - global suppression or far from source
// In some distant config file:
// checkstyle.ignore = ["MethodLength"]
See pull-request skill for the full self-review checklist before creating or
updating a PR.
Don't waste reviewer time on issues you could have caught yourself.