$npx -y skills add flutter/agent-plugins --skill code-documentationGuide for writing effective code documentation, including docstrings, JSDoc, dartdoc, and implementation comments. Use this skill when writing new code, adding features, or improving existing documentation in Dart, Python, or TypeScript to ensure clarity and maintainability.
| 1 | # Code Documentation Skill |
| 2 | |
| 3 | This skill provides comprehensive guidelines for documenting code, prioritizing user-centric writing, clarity, and consistency. |
| 4 | |
| 5 | ## 1. General Philosophy |
| 6 | |
| 7 | - **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. |
| 8 | - **Explain "Why"**: Explain _why_ code exists and _how_ to use it effectively, since the code signature already tells _what_ it does. |
| 9 | - **Be Concise**: Omit fluff. Avoid merely restating the code name, as it is not helpful. |
| 10 | - **Consistency**: Use standard terminology and consistent formatting. |
| 11 | - **Public APIs**: Document all public APIs (classes, members, top-level functions) without exception. |
| 12 | - **Code Samples**: Strongly consider adding code samples to explain usage. |
| 13 | |
| 14 | ## 2. General Structure |
| 15 | |
| 16 | Follow this general structure for documentation comments across languages: |
| 17 | |
| 18 | 1. **Summary Sentence**: Start with a single-sentence summary on the first line, ending with a period. |
| 19 | 2. **Blank Line**: Follow the summary with a blank line. |
| 20 | 3. **Details**: Add paragraphs, code samples, or lists as needed to explain parameters, return values, exceptions, and behavior. |
| 21 | 4. **Annotations**: Place doc comments **before** any metadata annotations. |
| 22 | |
| 23 | ## 3. Writing Guidelines |
| 24 | |
| 25 | ### Brevity & Style |
| 26 | |
| 27 | - **Avoid Fluff**: Omit "This class...", "This method...", "Is used to...", "Note that...". |
| 28 | - _Bad_: "This method is used to calculate the total." |
| 29 | - _Good_: "Calculates the total." |
| 30 | - **Third-Person Verbs**: Start function/method docs with a third-person singular verb. |
| 31 | - _Examples_: "Returns...", "Calculates...", "Updates...", "Creates...". |
| 32 | - **Noun Phrases**: Start variable/property docs with a noun phrase. |
| 33 | - _Examples_: "The current color.", "A list of active users.". |
| 34 | - **Booleans**: Always start with "Whether" (or similar clear indicator). |
| 35 | - _Good_: "Whether this widget is enabled." |
| 36 | - _Bad_: "If this widget is enabled...", "True if...", "Flag to indicate...". |
| 37 | - **Avoid Jargon**: Use plain English unless the term is a widely accepted standard (e.g., "HTTP", "URL"). |
| 38 | |
| 39 | ### Formatting |
| 40 | |
| 41 | - **Sparingly**: Use Markdown features (bold, lists) sparingly. |
| 42 | - **No HTML**: Avoid HTML unless strictly necessary and supported by the documentation tool. |
| 43 | - **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). |
| 44 | |
| 45 | ## 4. Implementation Comments |
| 46 | |
| 47 | 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. |
| 48 | |
| 49 | ## 5. Review Checklist |
| 50 | |
| 51 | Use this checklist to verify your documentation: |
| 52 | |
| 53 | 1. [ ] **Summary**: Ensure every public member starts with a one-sentence summary ending in a period. |
| 54 | 2. [ ] **Brevity**: Remove "This class..." or "This function..." fluff. |
| 55 | 3. [ ] **Completeness**: Document strict constraints (e.g., "must not be null") and exceptions. |
| 56 | 4. [ ] **Examples**: Consider adding a code sample for complex widgets or methods. |
| 57 | |
| 58 | ## 6. Language Specific Instructions |
| 59 | |
| 60 | Refer to the language guides for detailed instructions on structure, linking, and framework-specific patterns: |
| 61 | |
| 62 | - **Dart / Flutter**: [references/dart.md](references/dart.md) |
| 63 | - **TypeScript / JavaScript**: [references/typescript.md](references/typescript.md) |
| 64 | - **Python**: [references/python.md](references/python.md) |