Chuyển đến nội dung
Skillpedia
Lập trình chung33k · #8736

clean-code

Skill này làm gì

Skill này cung cấp cho AI của bạn các tiêu chuẩn viết code thực dụng, ưu tiên code đơn giản và rõ ràng. Nó dành cho lập trình viên muốn code sạch mà không bị thiết kế quá phức tạp.

Khi nào nên dùng

  • ✓Khi bạn yêu cầu agent viết hoặc xem lại code và muốn nó được giữ đơn giản.
  • ✓Khi code có hàm dài, tên không rõ ràng hoặc lồng nhau sâu.
  • ✓Khi bạn muốn tránh xây dựng các tính năng chưa cần thiết.

Liên kết skill

https://github.com/davila7/claude-code-templates/blob/main/cli-tool/components/skills/development/clean-code/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/davila7/claude-code-templates/blob/main/cli-tool/components/skills/development/clean-code/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Hãy tái cấu trúc hàm này để nó đơn giản hơn và dễ đọc hơn.”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Skill đưa cho agent các quy tắc về đặt tên, kích thước hàm và cấu trúc, cùng các nguyên tắc như DRY và KISS. Agent áp dụng chúng khi viết hoặc dọn dẹp code.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

Clean Code - Pragmatic AI Coding Standards

CRITICAL SKILL - Be concise, direct, and solution-focused.


Core Principles

Principle Rule
SRP Single Responsibility - each function/class does ONE thing
DRY Don't Repeat Yourself - extract duplicates, reuse
KISS Keep It Simple - simplest solution that works
YAGNI You Aren't Gonna Need It - don't build unused features
Boy Scout Leave code cleaner than you found it

Naming Rules

Element Convention
Variables Reveal intent: userCount not n
Functions Verb + noun: getUserById() not user()
Booleans Question form: isActive, hasPermission, canEdit
Constants SCREAMING_SNAKE: MAX_RETRY_COUNT

Rule: If you need a comment to explain a name, rename it.


Function Rules

Rule Description
Small Max 20 lines, ideally 5-10
One Thing Does one thing, does it well
One Level One level of abstraction per function
Few Args Max 3 arguments, prefer 0-2
No Side Effects Don't mutate inputs unexpectedly

Code Structure

Pattern Apply
Guard Clauses Early returns for edge cases
Flat > Nested Avoid deep nesting (max 2 levels)
Composition Small functions composed together
Colocation Keep related code close

AI Coding Style

Situation Action
User asks for feature Write it directly
User reports bug Fix it, don't explain
No clear requirement Ask, don't assume

Anti-Patterns (DON'T)

❌ Pattern ✅ Fix
Comment every line Delete obvious comments
Helper for one-liner Inline the code
Factory for 2 objects Direct instantiation
utils.ts with 1 function Put code where used
"First we import..." Just write code
Deep nesting Guard clauses
Magic numbers Named constants
God functions Split by responsibility

🔴 Before Editing ANY File (THINK FIRST!)

Before changing a file, ask yourself:

Question Why
What imports this file? They might break
What does this file import? Interface changes
What tests cover this? Tests might fail
Is this a shared component? Multiple places affected

Quick Check:

File to edit: UserService.ts
└── Who imports this? → UserController.ts, AuthController.ts
└── Do they need changes too? → Check function signatures

🔴 Rule: Edit the file + all dependent files in the SAME task. 🔴 Never leave broken imports or missing updates.


Summary

Do Don't
Write code directly Write tutorials
Let code self-document Add obvious comments
Fix bugs immediately Explain the fix first
Inline small things Create unnecessary files
Name things clearly Use abbreviations
Keep functions small Write 100+ line functions

Remember: The user wants working code, not a programming lesson.


🔴 Self-Check Before Completing (MANDATORY)

Before saying "task complete", verify:

Check Question
✅ Goal met? Did I do exactly what user asked?
✅ Files edited? Did I modify all necessary files?
✅ Code works? Did I test/verify the change?
✅ No errors? Lint and TypeScript pass?
✅ Nothing forgotten? Any edge cases missed?

🔴 Rule: If ANY check fails, fix it before completing.


Verification Scripts (MANDATORY)

🔴 CRITICAL: Each agent runs ONLY their own skill's scripts after completing work.

Agent → Script Mapping

Agent Script Command
frontend-specialist UX Audit python ~/.claude/skills/frontend-design/scripts/ux_audit.py .
frontend-specialist A11y Check python ~/.claude/skills/frontend-design/scripts/accessibility_checker.py .
backend-specialist API Validator python ~/.claude/skills/api-patterns/scripts/api_validator.py .
mobile-developer Mobile Audit python ~/.claude/skills/mobile-design/scripts/mobile_audit.py .
database-architect Schema Validate python ~/.claude/skills/database-design/scripts/schema_validator.py .
security-auditor Security Scan `python ~/.c
Câu hỏi thường gặp

DRY và KISS là gì?

DRY nghĩa là đừng lặp lại chính mình, còn KISS nghĩa là giữ giải pháp đơn giản nhất có thể.

Các quy tắc về hàm là gì?

Hàm nên nhỏ, chỉ làm một việc, nhận ít tham số và tránh tác dụng phụ không mong muốn.

Nó có ưu tiên chú thích không?

Không. Nó ưu tiên tên rõ ràng, và cho rằng tên cần chú thích thì nên đổi tên.

Chi tiết

Mô tả gốc của tác giả

Pragmatic coding standards - concise, direct, no over-engineering, no unnecessary comments

repo: davila7/claude-code-templates

Độ phổ biến

Sao GitHub
33k
Vị trí xếp hạng
#8736
Giấy phép
MIT
Cập nhật
2/11/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự