بنقرة واحدة
coding-standards
代碼實作階段觸發。強制執行統一的編碼規範,支援 Java、TypeScript、Go 多語言。包含 Input/Output 模式、依賴注入、不可變物件等規範,確保代碼風格一致性。
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
القائمة
代碼實作階段觸發。強制執行統一的編碼規範,支援 Java、TypeScript、Go 多語言。包含 Input/Output 模式、依賴注入、不可變物件等規範,確保代碼風格一致性。
التثبيت باستخدام Codex أو Claude انسخ هذا Prompt والصقه في Codex أو Claude أو مساعد آخر ليراجع صفحة Skill ويثبّتها لك.
استنادا إلى تصنيف SOC المهني
Automated code review that checks code quality, Clean Architecture compliance, DDD patterns, coding standards, and spec traceability.
從規格目錄的 acceptance.yaml 生成/維護 BDD/ezSpec 測試。使用類似 Gherkin 語法,AI 自動產生 step definition(開發人員不需要手寫),驗收測試規格即為 Executable Specification。
在單元測試通過後觸發。透過引入人工錯誤(Mutants)來「測試你的測試」,確保測試案例具有足夠的錯誤偵測能力,建立對驗證機制的信任(Trust the Verification)。
驗證規格檔案的完整性與一致性,確保所有必要的規格元素都已定義且符合標準格式。
Replace with description of the skill and when Claude should use it.
協調多個 AI 模型(ChatGPT、Gemini、Codex、QWEN、Claude)進行三角驗證,確保「Specification == Program == Test」一致性。過濾假警報後輸出報告,大幅減少人工介入時間。
| name | coding-standards |
| description | 代碼實作階段觸發。強制執行統一的編碼規範,支援 Java、TypeScript、Go 多語言。包含 Input/Output 模式、依賴注入、不可變物件等規範,確保代碼風格一致性。 |
強制執行統一的編碼規範,確保 AI 生成的代碼風格高度一致,降低人類審閱成本。
根據專案語言選擇對應的規範:
| 語言 | 參考文件 | 說明 |
|---|---|---|
| Java | 本文件 | Spring Boot / Jakarta EE |
| Java | references/JAVA_CLEAN_ARCH.md | Clean Architecture 詳細結構 |
| TypeScript | references/TYPESCRIPT.md | Node.js / Deno / Bun |
| Go | references/GOLANG.md | Standard Go Project Layout |
| Rust | references/RUST.md | Cargo / Tokio async runtime |
當被其他 Sub-agent 呼叫時,本 Skill 提供語言特定的編碼規範:
command-sub-agent 呼叫 → 提供 Use Case / Command Handler 的編碼規範
query-sub-agent 呼叫 → 提供 Query Handler / Read Model 的編碼規範
reactor-sub-agent 呼叫 → 提供 Event Handler 的編碼規範
public class CreateOrderUseCase {
// ✅ Input 定義為靜態內部類別
public static class Input {
private final CustomerId customerId;
private final List<OrderItemRequest> items;
private final ShippingAddress address;
public Input(CustomerId customerId,
List<OrderItemRequest> items,
ShippingAddress address) {
// 可在此進行基本驗證
Objects.requireNonNull(customerId, "customerId must not be null");
Objects.requireNonNull(items, "items must not be null");
if (items.isEmpty()) {
throw new IllegalArgumentException("items must not be empty");
}
this.customerId = customerId;
this.items = List.copyOf(items);
this.address = address;
}
// Getters
public CustomerId getCustomerId() { return customerId; }
public List<OrderItemRequest> getItems() { return items; }
public ShippingAddress getAddress() { return address; }
}
// ✅ Output 定義為靜態內部類別
public static class Output {
private final OrderId orderId;
private final OrderStatus status;
private final LocalDateTime createdAt;
public Output(OrderId orderId, OrderStatus status, LocalDateTime createdAt) {
this.orderId = orderId;
this.status = status;
this.createdAt = createdAt;
}
// Getters
public OrderId getOrderId() { return orderId; }
public OrderStatus getStatus() { return status; }
public LocalDateTime getCreatedAt() { return createdAt; }
}
// ✅ 主要執行方法,接收 Input,回傳 Output
public Output execute(Input input) {
// 業務邏輯
}
}
// ❌ 禁止:直接使用多個參數
public OrderResult createOrder(String customerId, List<Item> items, String address) {
// 這樣做會讓介面難以維護
}
// ❌ 禁止:使用 Map 作為輸入輸出
public Map<String, Object> createOrder(Map<String, Object> params) {
// 這樣做會失去型別安全
}
// ✅ 正確:使用 @Configuration + @Bean
@Configuration
public class UseCaseConfiguration {
@Bean
public CreateOrderUseCase createOrderUseCase(
OrderRepository orderRepository,
InventoryService inventoryService,
EventPublisher eventPublisher) {
return new CreateOrderUseCase(
orderRepository,
inventoryService,
eventPublisher
);
}
@Bean
public CancelOrderUseCase cancelOrderUseCase(
OrderRepository orderRepository,
PaymentGateway paymentGateway) {
return new CancelOrderUseCase(orderRepository, paymentGateway);
}
}
// ✅ Use Case 類別保持純淨,無 Spring 註解
public class CreateOrderUseCase {
private final OrderRepository orderRepository;
private final InventoryService inventoryService;
private final EventPublisher eventPublisher;
// 建構子注入
public CreateOrderUseCase(
OrderRepository orderRepository,
InventoryService inventoryService,
EventPublisher eventPublisher) {
this.orderRepository = orderRepository;
this.inventoryService = inventoryService;
this.eventPublisher = eventPublisher;
}
}
// ❌ 禁止:在 Use Case 上使用 @Component/@Service
@Service // ❌ 不要這樣做
public class CreateOrderUseCase {
@Autowired // ❌ 不要這樣做
private OrderRepository orderRepository;
}
以下情況可使用 @Component 系列註解:
| 類型 | 允許使用 | 說明 |
|---|---|---|
| Controller | @RestController | 展示層入口點 |
| Repository 實作 | @Repository | Infrastructure 層 |
| Event Listener | @Component | 技術性元件 |
| Scheduled Task | @Component | 技術性元件 |
// ✅ 動詞 + 名詞 + UseCase
CreateOrderUseCase
CancelOrderUseCase
UpdateCustomerProfileUseCase
// ✅ CQRS Command Handler
CreateOrderCommandHandler
CancelOrderCommandHandler
// ✅ CQRS Query Handler
GetOrderByIdQueryHandler
ListOrdersByCustomerQueryHandler
// ✅ Use Case 統一使用 execute()
public Output execute(Input input)
// ✅ Command Handler 統一使用 handle()
public void handle(CreateOrderCommand command)
// ✅ Query Handler 統一使用 handle()
public OrderDto handle(GetOrderByIdQuery query)
public static class Input {
private final CustomerId customerId; // ✅ final
private final List<OrderItemRequest> items;
public Input(CustomerId customerId, List<OrderItemRequest> items) {
this.customerId = customerId;
this.items = List.copyOf(items); // ✅ 防禦性複製
}
// ✅ 只有 Getter,沒有 Setter
public CustomerId getCustomerId() { return customerId; }
public List<OrderItemRequest> getItems() {
return items; // 已經是不可變的
}
}
// ✅ 定義領域特定例外
public class OrderNotFoundException extends DomainException {
public OrderNotFoundException(OrderId orderId) {
super("Order not found: " + orderId.getValue());
}
}
public class InsufficientInventoryException extends DomainException {
public InsufficientInventoryException(ProductId productId, int requested, int available) {
super(String.format(
"Insufficient inventory for product %s: requested %d, available %d",
productId.getValue(), requested, available
));
}
}
rules:
- id: no-component-on-usecase
pattern: "@(Component|Service).*class.*UseCase"
message: "Use @Bean configuration instead of @Component on UseCase classes"
severity: error
- id: no-autowired-field
pattern: "@Autowired\\s+private"
message: "Use constructor injection instead of field injection"
severity: error
- id: require-input-output-class
pattern: "class.*UseCase.*execute\\((?!Input)"
message: "UseCase.execute() should accept Input inner class"
severity: warning