Skip to content

improve inline docs #15

@jinglescode

Description

@jinglescode

AI readiness and developer clarity, your inline docs should include:

  • A clear description of what the function/class/module does, including its purpose and context.
  • Parameter documentation with types, constraints, and example values.
  • Return value documentation with type and shape of the result, and example values.
  • Usage examples, both minimal and full code examples.
  • Example inputs and expected outputs, so AI and humans can understand end-to-end usage.
  • Error conditions and edge cases, including what gets thrown or returned on failure.

inline doc template for functions:

/**
 * @function [FunctionName]
 * @description
 * Short and clear one-line summary of what this function does.
 * Mention the Cardano-specific context if relevant.
 *
 * @purpose
 * Explain why a developer would use this, what problem it solves, and when it should be used.
 *
 * @param {<Type>} paramName - Description of this parameter, including:
 *   - Purpose
 *   - Constraints (e.g., must be non-empty, valid Bech32 address, etc.)
 *   - Example value: `addr1qxy...`
 *
 * @param {<Type>} anotherParamName - Description...
 *
 * @returns {<Type>} Description of the return value:
 *   - Shape of the object or primitive
 *   - Key fields and their meaning
 *   - Example value or structure
 *
 * @throws {<ErrorType>} When this error is thrown and why
 * @throws {<AnotherErrorType>} Another possible error
 *
 * @example
 * // Minimal usage
 * const result = mesh.functionName("inputValue");
 *
 * @see mesh.relatedFunction
 * @see https://meshjs.dev/docs/path/to/doc
 */
  • @function: clearly labels the entity for linting & doc generation.
  • @description / @purpose: split so AI & humans see what it does vs why it’s used.
  • @param: includes type, purpose, constraints, and example value.
  • @returns: includes type and example output.
  • @throws: lists errors for better developer & AI safety.
  • @example: ensures we have explicit input/output mapping.
  • @see: links to related functions or docs for context.

example: txIn

/**
 * @function txIn
 * @description
 * Sets an input UTxO for the transaction being built.
 * Can handle both PubKey and Plutus script inputs depending on builder state.
 *
 * @purpose
 * Used when specifying which UTxO(s) should be consumed as inputs in a transaction.
 * Supports optional asset amounts, addresses, and reference script sizes for offline building.
 *
 * @param {string} txHash
 *   The transaction hash of the input UTxO.
 *   - Must be a valid 64-character hex string.
 *   - Example: `"9f3a2b...c8d4"`.
 *
 * @param {number} txIndex
 *   The transaction index of the input UTxO within the transaction’s outputs.
 *   - Must be a non-negative integer.
 *   - Example: `0`.
 *
 * @param {Asset[]} [amount]
 *   (Optional) Array of asset objects representing the value at the UTxO.
 *   - Each asset must have a `unit` and `quantity`.
 *   - Example: `[{ unit: "lovelace", quantity: "5000000" }]`.
 *
 * @param {string} [address]
 *   (Optional) The Bech32 address of the input UTxO.
 *   - Must be a valid Cardano address.
 *   - Example: `"addr1qxy..."`.
 *
 * @param {number} [scriptSize]
 *   (Optional) Size in bytes of the reference script at this input.
 *   - If no script exists, explicitly set `0` for offline transaction building.
 *   - Example: `0` or `512`.
 *
 * @returns {MeshTxBuilder}
 *   Returns the current MeshTxBuilder instance for method chaining.
 *
 * @throws {Error}
 *   Throws if `txHash` is invalid or `txIndex` is negative.
 *
 * @example
 * // Minimal usage
 * txBuilder.txIn("9f3a2b...c8d4", 0);
 *
 * @see MeshTxBuilder
 * @see https://meshjs.dev/docs/txBuilder/txIn
 */

inline doc template for constants:

/**
 * @constant [CONSTANT_NAME]
 * @description
 * Short, clear one-liner of what this constant represents.
 * Mention Cardano/UTxO context or units if relevant (e.g., lovelace, bytes).
 *
 * @purpose
 * Why a developer would reference this value (defaults, limits, protocol constant, etc.).
 *
 * @example
 * // In context
 * const minFee = Math.max(calculatedFee, [CONSTANT_NAME]);
 *
 * @see https://meshjs.dev/docs/path/to/doc
 * @see mesh.relatedConstantOrFunction
 */

inline doc template for types:

/**
 * @typealias [TypeName]
 * @description
 * One-line definition of the shape and its role (domain model, DTO, on-chain concept, etc.).
 * Include Cardano specifics if relevant (Bech32, policy IDs, datum CBOR, etc.).
 *
 * @purpose
 * Why this type exists, where it’s used, and how it composes with other Mesh types.
 *
 * @property {<Type>} fieldName
 *   Description of the field:
 *   - Purpose
 *   - Constraints (e.g., valid Bech32 address, 64-char hex)
 *   - Example: `<example value>`
 *
 * @property {<Type>} anotherField
 *   Description...
 *
 * @remarks
 * **Invariants / edge cases**
 * - Describe any invariants (e.g., `quantity` must be a non-negative decimal string).
 * - Note optional vs required properties and serialization gotchas.
 *
 * @example
 * // Full example with realistic values
 * const y: [TypeName] = {
 *   fieldName: "<value>",
 *   anotherField: 123,
 * };
 *
 * @see mesh.RelatedType
 * @see https://meshjs.dev/docs/path/to/type
 */
export type [TypeName] = {
  fieldName: <Type>;
  anotherField?: <Type>;
};
  • also reference existing website to see if any examples can be ported in
  • feel free to use LLM in editor to make those inline docs, some quality assurance checks will be needed

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

Status

In Progress

Relationships

None yet

Development

No branches or pull requests

Issue actions