code-documentation

作者: flutter

編寫有效程式碼文件的指南,包括 docstrings、JSDoc、dartdoc 和實作註解。在編寫新程式碼、新增…時使用此技能。

npx skills add https://github.com/flutter/agent-plugins --skill code-documentation

Code Documentation Skill

This skill provides comprehensive guidelines for documenting code, prioritizing user-centric writing, clarity, and consistency.

1. General Philosophy

  • User-Centric: Write for the person using your API. If you had to look up how to use something, document it so others don't have to.
  • Explain "Why": Explain why code exists and how to use it effectively, since the code signature already tells what it does.
  • Be Concise: Omit fluff. Avoid merely restating the code name, as it is not helpful.
  • Consistency: Use standard terminology and consistent formatting.
  • Public APIs: Document all public APIs (classes, members, top-level functions) without exception.
  • Code Samples: Strongly consider adding code samples to explain usage.

2. General Structure

Follow this general structure for documentation comments across languages:

  1. Summary Sentence: Start with a single-sentence summary on the first line, ending with a period.
  2. Blank Line: Follow the summary with a blank line.
  3. Details: Add paragraphs, code samples, or lists as needed to explain parameters, return values, exceptions, and behavior.
  4. Annotations: Place doc comments before any metadata annotations.

3. Writing Guidelines

Brevity & Style

  • Avoid Fluff: Omit "This class...", "This method...", "Is used to...", "Note that...".
    • Bad: "This method is used to calculate the total."
    • Good: "Calculates the total."
  • Third-Person Verbs: Start function/method docs with a third-person singular verb.
    • Examples: "Returns...", "Calculates...", "Updates...", "Creates...".
  • Noun Phrases: Start variable/property docs with a noun phrase.
    • Examples: "The current color.", "A list of active users.".
  • Booleans: Always start with "Whether" (or similar clear indicator).
    • Good: "Whether this widget is enabled."
    • Bad: "If this widget is enabled...", "True if...", "Flag to indicate...".
  • Avoid Jargon: Use plain English unless the term is a widely accepted standard (e.g., "HTTP", "URL").

Formatting

  • Sparingly: Use Markdown features (bold, lists) sparingly.
  • No HTML: Avoid HTML unless strictly necessary and supported by the documentation tool.
  • Parameters/Returns/Exceptions: Use prose to describe parameters, return values, and thrown exceptions. Do not rely solely on tags like @param unless mandated by the language standard (e.g., Javadoc).

4. Implementation Comments

Ensure implementation comments (//) are accurate, relevant, factual, and provide information that is not readily understandable from the code. Remove or reword comments that do not meet these criteria. If an implementation comment provides information useful to an API consumer that is not already in the documentation comments, move it to the documentation comments.

5. Review Checklist

Use this checklist to verify your documentation:

  1. Summary: Ensure every public member starts with a one-sentence summary ending in a period.
  2. Brevity: Remove "This class..." or "This function..." fluff.
  3. Completeness: Document strict constraints (e.g., "must not be null") and exceptions.
  4. Examples: Consider adding a code sample for complex widgets or methods.

6. Language Specific Instructions

Refer to the language guides for detailed instructions on structure, linking, and framework-specific patterns:

來自 flutter 的更多技能

dart-modern-features
flutter
為了尋找現代化的候選對象:
flutter-fix-layout-issues
flutter
使用 Dart 和 Flutter MCP 工具修復 Flutter 佈局錯誤(溢出、無限制約束)。適用於處理「RenderFlex overflowed」、「Vertical…」等問題。
adding-release-notes
flutter
在 DevTools 發行說明中新增使用者面向的變更描述。用於在 NEXT_RELEASE_NOTES.md 檔案中記錄改進、修正或新功能。
reviewing-devtools-prs
flutter
DevTools 儲存庫專用的 PR 審查工作流程,強制執行 DevTools 風格指南與常見審查模式。用於審查以下專案中的拉取請求時…
dart-use-primary-constructors
flutter
協助使用者撰寫語法與語意正確的 Dart 主要建構子,並遷移/使用新的建構子語法、空主體分號語法、…
api-review
flutter
根據規範的 API 設計指南審查指定的程式碼。當使用者要求進行 API 審查或檢查程式碼是否符合 API 設計時,請使用此技能。
flutter-accessibility
flutter
在 Flutter 應用程式中實作 WCAG 2 與 EN 301 549 無障礙標準及自適應佈局。強制執行語意標註、觸控目標尺寸(最小 48x48 dp)以及文字對比度(小字 4.5:1,大字 3:1),涵蓋行動裝置、網頁與桌面平台。提供網頁語意初始化、互動元件包裝、基於螢幕尺寸的佈局切換,以及鍵盤/滑鼠輸入處理的決策邏輯。包含透過 FocusTraversalGroup 進行的焦點導覽管理,以及...
flutter-accessibility-audit
flutter
透過 widget_inspector 觸發無障礙掃描,並自動在原始碼中新增 Semantics 元件或補上遺漏的標籤。