Chuyển đến nội dung
Skillpedia
Tài liệu kỹ thuật40k · #7268

lean-comments

Skill này làm gì

Công cụ này giúp mã chương trình gọn gàng và dễ hiểu. Nó kiểm tra xem các chú thích có thật sự cần thiết không và có giải thích “vì sao” không, thay vì chỉ lặp lại điều mã đã thể hiện.

Khi nào nên dùng

  • ✓Khi bạn thêm chú thích mới vào mã.
  • ✓Khi bạn xem lại các chú thích hiện có để đảm bảo chúng hữu ích.
  • ✓Khi mã khó hiểu và cần một lời giải thích rõ ràng.

Liên kết skill

https://github.com/github/awesome-copilot/blob/main/skills/lean-comments/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/github/awesome-copilot/blob/main/skills/lean-comments/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 xem lại các chú thích trong đoạn mã này để đảm bảo chúng thật sự cần thiết và giải thích được 'vì sao'.”

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

Cách hoạt động

Công cụ xem xét liệu một lập trình viên có kinh nghiệm có mất thông tin quan trọng nếu chú thích không có mặt hay không. Nó ưu tiên xóa những chú thích chỉ lặp lại mã hoặc quá hiển nhiên.

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.

Lean Comments

Goal

Keep the smallest amount of high-value commentary necessary to make a codebase easier and safer to understand and maintain.

The default is no comment.

A comment must preserve meaningful information that a competent maintainer cannot reasonably recover from the code, names, types, signatures, structure, tests, configuration, or nearby context.

Comments are not labels, narration, decoration, declaration summaries, change logs, or substitutes for clear code.

Reader model

Write for a competent maintainer reading the repository at HEAD months later, without access to the current conversation, prompt, diff, pull request, issue discussion, review discussion, or implementation process.

Document the durable state, contract, constraint, or rationale of the code as it exists. Do not assume the reader knows what changed, what came before, or what was discussed unless that context is deliberately preserved in a reliable project source.

Authority and evidence

Use this skill as the comment-policy authority when it is active.

Use language, framework, library, or infrastructure skills to determine whether a non-obvious constraint is real, not to override this skill's necessity test.

Honor explicit current repository requirements, public API documentation requirements, tooling contracts, and generated-source rules. Do not infer a documentation requirement merely from existing comment density or precedent.

Base retained or newly written rationale on evidence from the repository, tests, configuration, official API behavior, project documentation, issue tracker, ADRs, specifications, or another reliable source.

Never invent a security reason, performance reason, business rule, compatibility requirement, API constraint, historical reason, architectural rationale, or external limitation to justify commentary.

If no supported non-obvious reason exists, remove or omit it.

Core decision rule

Before retaining or adding ordinary commentary, mentally remove it and ask:

Would a competent maintainer lose meaningful, non-obvious information if this comment did not exist?

If no, remove or omit it.

If uncertain, prefer no comment unless repository evidence demonstrates that the information matters.

If yes, retain only the minimum information necessary.

Never preserve a comment merely because it is correct, harmless, already present, grammatically polished, written as a warning, related to security or validation, related to internal or public state, or attached to an exported declaration.

The information itself must justify the comment.

Decision order

Evaluate existing and proposed commentary in this order:

  1. Delete or omit if the information is already clear without it
  2. Express through code if a tiny behavior-preserving readability improvement removes the need for it
  3. Shorten if it is necessary but contains unnecessary information or words
  4. Rewrite if it is necessary but unclear, inaccurate, stale, awkward, or inconsistent
  5. Use declaration documentation if the information belongs to the declaration's contract, semantics, or intended usage
  6. Keep unchanged only if it is already necessary, minimal, accurate, durable, and correctly styled

Always decide necessity before wording.

Do not polish an unnecessary comment or convert one into documentation.

What deserves an implementation comment

Use an implementation comment when it preserves non-obvious information such as:

  • Why intentionally surprising code exists
  • An external constraint or compatibility requirement
  • An important invariant or subtle edge case
  • A meaningful tradeoff or required workaround
  • Non-obvious coupling
  • An ordering, timing, lifecycle, concurrency, performance, or security constraint
  • A reason an apparently simpler implementation would be incorrect

Prefer comments that explain why something matters.

Comments that merely explain what the code does should normally be removed.

Remove low-value commentary

Remove comments that merely:

  • Restate or translate the code into prose
  • Narrate the next statement or obvious control flow
  • Explain an obvious guard clause, return, assignment, or branch
  • Describe an obvious fetch, validation, transformation, mapping, filtering, creation, update, or deletion
  • Repeat a declaration name, property name, type, signature, parameter, or return type
  • Label or summarize a declaration

…

Câu hỏi thường gặp

“Mã nguồn” là gì?

Đó là văn bản do lập trình viên viết, cho máy tính biết phải làm gì. Nó giống như công thức nấu ăn cho máy tính.

“Chú thích” trong mã là gì?

Đó là các ghi chú trong mã mà lập trình viên dùng để giải thích phần khó hiểu hoặc lý do của một quyết định. Máy tính bỏ qua chúng.

Vì sao chú thích tốt lại quan trọng?

Chú thích tốt giúp các lập trình viên khác (hoặc chính bạn trong tương lai) hiểu mã nhanh hơn, từ đó dễ bảo trì và sửa lỗi hơn.

Chi tiết

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

Audits, writes, and refines maintained first-party source-code comments and declaration-level documentation across languages. Use when adding, editing, reviewing, cleaning up, or auditing comments, doc comments, docstrings, TODO, FIXME, NOTE, suppressions, or other source commentary, including while modifying code and deciding whether a comment is warranted at all. Defaults to no comment unless it

repo: github/awesome-copilot

Độ phổ biến

Sao GitHub
40k
Vị trí xếp hạng
#7268
Giấy phép
MIT
Cập nhật
15/10/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ự