Style Guide (v.1.1.0)

Concise rules the codebase and all agent suggestions should follow.

1. General Principles

2. TypeScript Conventions

3. Naming

4. JSDoc Template

For every public/exported function or public methods (and important internal helpers):

/**
 * One-line summary (starts with a verb, ends without period if short)
 *
 * Longer description (optional) explaining rationale or algorithm. Mention spec refs if relevant.
 *
 * Edge cases:
 *  - bullet 1
 *  - bullet 2
 *
 * @param {Type} name Description (units, accepted range, behavior on bounds)
 * @returns {Type} Description (units, range, side effects)
 * @throws {ErrorType} When it is thrown (only if the function throws)
 */

Rules:

5. Error Handling & Validation

6. Logging

In Matterbridge and its plugins the logger is always AnsiLogger.

7. Formatting & Lint

8. Tests

9. Performance

10. Agents

11. File Header Blocks

Every source and test file starts with a JSDoc header block, before anything else except a shebang.

12. Deprecation

13. Commit Messages

Follow Conventional Commits. The full rules are in .github/commit-message-instructions.html.

14. Changelog

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

15. Example (Reference)

/**
 * Convert lux to the Matter encoded illuminance value
 *
 * Matter spec § 2.2.5.1: MeasuredValue = 10,000 x log10(illuminance) + 1, in the range 1 to 0xFFFE.
 *
 * Edge cases:
 *  - < 1 or non-finite -> 0 (too low to be measured)
 *  - Caps at 0xFFFE
 *
 * @param {number} lux Illuminance in lux (>= 0).
 * @returns {number} Encoded value (0, or 1..0xFFFE)
 */
function luxToMatterExample(lux: number): number {
  if (!Number.isFinite(lux) || lux < 1) return 0;
  return Math.min(Math.round(10000 * Math.log10(lux) + 1), 0xfffe);
}

Short, opinionated. If a rule isn't helping, propose a PR to adjust.