Style Guide

Concise rules the codebase and Copilot 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)
 */

Rules:

5. Error Handling & Validation

6. Logging

The logger is always AnsiLogger.

7. Formatting & Lint

8. Tests

9. Performance

10. Copilot Prompting Hints

Placing this file at root lets Copilot pick patterns. Reinforce by:

11. File Header Blocks

12. Deprecation

13. Commit Messages (conventional subset)

14. Example (Reference)

/**
 * Convert lux to Matter encoded illuminance value.
 *
 * Edge cases:
 *  - <=0 or non-finite -> 0
 *  - Caps at 0xFFFE
 *
 * @param {number} lux Illuminance in lux (>=0).
 * @returns {number} Encoded value (0..0xFFFE)
 */
function luxToMatterExample(lux: number): number {
  if (!Number.isFinite(lux) || lux <= 0) return 0;
  return Math.round(Math.min(10000 * Math.log10(lux), 0xfffe));
}

15. Creating Jest test

Always remember we are in ESM module with ts-jest.

So use jest.unstable_mockModule and not jest.mock.

16. Running Jest test

Always use

npm run test:coverage -- yourTest.test.ts


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