|
| 1 | +--- |
| 2 | +name: standard-jsdoc |
| 3 | +description: Write, insert, or update Effect public API JSDoc so it satisfies the standard-jsdoc oxlint rule. Use when adding or fixing JSDoc comments, resolving standard-jsdoc diagnostics, preparing docs for JSON extraction, or reviewing public API documentation. |
| 4 | +--- |
| 5 | + |
| 6 | +Use this skill to write well-formed JSDoc for Effect public APIs. |
| 7 | + |
| 8 | +## Required documentation shape |
| 9 | + |
| 10 | +Use a normal multiline JSDoc comment in TypeScript source: |
| 11 | + |
| 12 | +```ts |
| 13 | +/** |
| 14 | + * Short description as one paragraph. |
| 15 | + * |
| 16 | + * **When to use** |
| 17 | + * |
| 18 | + * Optional practical usage guidance. |
| 19 | + * |
| 20 | + * **Details** |
| 21 | + * |
| 22 | + * Optional details for complex APIs, options, overloads, or behavior. |
| 23 | + * |
| 24 | + * **Gotchas** |
| 25 | + * |
| 26 | + * Optional edge cases, footguns, or surprising behavior. |
| 27 | + * |
| 28 | + * **Example** (Short title) |
| 29 | + * |
| 30 | + * Optional prose explaining the example. |
| 31 | + * |
| 32 | + * ```ts |
| 33 | + * const result = example() |
| 34 | + * ``` |
| 35 | + * |
| 36 | + * @category constructors |
| 37 | + * @since 1.0.0 |
| 38 | + */ |
| 39 | +``` |
| 40 | + |
| 41 | +## Writing rules |
| 42 | + |
| 43 | +- Use sober, practical prose. |
| 44 | +- Do not use jargon when a plain word works. |
| 45 | +- Do not be clever. |
| 46 | +- Do not add filler sections. |
| 47 | +- The short description is required and must be exactly one paragraph. |
| 48 | +- Optional sections must appear in this order: |
| 49 | + 1. `**When to use**` |
| 50 | + 2. `**Details**` |
| 51 | + 3. `**Gotchas**` |
| 52 | +- Include an optional section only when it has useful, non-empty content. |
| 53 | +- `**When to use**` is important when the API has close alternatives, trade-offs, or `@see` tags. If `@see` tags are present, inspect the referenced APIs and add `**When to use**` when it helps readers choose between them. |
| 54 | +- Add `@see` only for APIs that are similar to the documented API but intended for different situations or usage patterns. Do not add `@see` for loosely related helpers, dependencies, implementation details, or general background links. |
| 55 | +- Before deciding whether to include `**Gotchas**`, inspect the implementation and nearby tests for edge cases, footguns, preconditions, surprising behavior, or important failure modes. Add `**Gotchas**` only when you find a real gotcha worth documenting. |
| 56 | +- Use exactly one blank line between the short description, sections, examples, and tags. |
| 57 | +- Do not use Markdown headings such as `# Heading` or ad hoc bold headings such as `**Notes**`; only the standard headings are allowed. |
| 58 | +- Examples must use `**Example** (Title)`, optional prose, and exactly one non-empty `ts` code fence. |
| 59 | +- Example titles must be unique after trimming and lowercasing. |
| 60 | +- Do not use `@example`. |
| 61 | +- Do not put TypeScript code fences outside `**Example** (Title)` sections. |
| 62 | +- Inline `{@link Symbol}` targets must resolve to TypeScript symbols; do not link to URLs with `{@link}`. |
| 63 | +- Do not document module-level comments; module JSDoc is ignored by this rule. |
| 64 | +- `@internal` means the item is ignored; do not rewrite it as public docs. |
| 65 | +- Default exports are ignored by this rule and do not need JSDoc. |
| 66 | +- Do not add unsupported constructs such as enums or empty exports in checked files. |
| 67 | + |
| 68 | +## Tag rules |
| 69 | + |
| 70 | +When multiple tags are present, keep them in this order: |
| 71 | + |
| 72 | +1. `@deprecated` |
| 73 | +2. `@default` |
| 74 | +3. `@see` |
| 75 | +4. `@category` |
| 76 | +5. `@since` |
| 77 | + |
| 78 | +Root declarations: |
| 79 | + |
| 80 | +- Require `@category`. |
| 81 | +- Require `@since` with stable semver like `1.2.3`. |
| 82 | +- May use `@deprecated` with a non-empty message. |
| 83 | +- May use repeated non-empty `@see` tags, but only for similar APIs with different usage patterns. |
| 84 | +- Must not use `@default`. |
| 85 | + |
| 86 | +Namespaces and declarations inside namespaces: |
| 87 | + |
| 88 | +- Require `@since` with stable semver like `1.2.3`. |
| 89 | +- May use optional `@category`. |
| 90 | +- May use `@deprecated` with a non-empty message. |
| 91 | +- May use repeated non-empty `@see` tags, but only for similar APIs with different usage patterns. |
| 92 | +- Must not use `@default`. |
| 93 | + |
| 94 | +Members: |
| 95 | + |
| 96 | +- JSDoc is optional. |
| 97 | +- When member JSDoc is present, it must follow the same short description, section, example, spacing, and tag-order rules. |
| 98 | +- May use optional `@since` with stable semver like `1.2.3`. |
| 99 | +- May use `@default` with a non-empty value. |
| 100 | +- May use `@deprecated` with a non-empty message. |
| 101 | +- May use repeated non-empty `@see` tags, but only for similar APIs with different usage patterns. |
| 102 | +- Must not use `@category`. |
| 103 | + |
| 104 | +## Updating existing JSDoc |
| 105 | + |
| 106 | +When fixing or updating existing docs: |
| 107 | + |
| 108 | +1. Preserve correct facts and examples. |
| 109 | +2. Rewrite the layout into the standard template. |
| 110 | +3. Move usage guidance into `**When to use**`; when `@see` tags are present, inspect the referenced APIs and explain selection guidance if useful. |
| 111 | +4. Move option, overload, and behavior details into `**Details**`. |
| 112 | +5. Move caveats into `**Gotchas**`; if no caveat is already documented, inspect the implementation and nearby tests before deciding whether a `**Gotchas**` section is warranted. |
| 113 | +6. Convert `@example` tags and loose `ts` fences into `**Example** (Title)` sections. |
| 114 | +7. Preserve valid `@see`, `@deprecated`, `@default`, `@category`, and `@since` tags. |
| 115 | +8. Remove `@see` tags that do not point to similar APIs with meaningfully different usage patterns. |
| 116 | +9. Remove sections that would be empty. |
| 117 | + |
| 118 | +## Validation |
| 119 | + |
| 120 | +After changing JSDoc governed by the rule, run the narrowest relevant validation: |
| 121 | + |
| 122 | +```sh |
| 123 | +pnpm test packages/tools/oxc/test/standard-jsdoc.test.ts |
| 124 | +pnpm check:tsgo |
| 125 | +``` |
| 126 | + |
| 127 | +If the changed package has generated docs, also run `pnpm docgen` from that package directory. |
0 commit comments