Concise rules the codebase and Copilot suggestions should follow.
strict typing; no any unless justified with a preceding comment // intentional any: reason.readonly or as const) for constant structures / lookup tables.as X unless unavoidable.createDevice, updateState).is/has/can/should (internal helpers); state flags in this project may keep existing names (intervalOnOff)._ only if intentionally unused yet (silencing ESLint); otherwise export or remove.UPPER_SNAKE_CASE only for process env or true constants; otherwise camelCase.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:
@param and @returns with explicit types (even if TS can infer) for consistency with lint rules.°C * 100, lux, mireds, Pa).@returns {Promise<Type>}.Number.isFinite(n); clamp with Math.min/Math.max.The logger is always AnsiLogger.
log.debug for verbose internal transitions.log.info for state changes & received commands.log.notice for notices.log.warn for recoverable anomalies (out‑of‑range adjusted, missing optional attribute).log.error only for failed operations that stop progress.log.fatal only for failed operations that are not recoverable.converts 100 lux to encoded value).Placing this file at root lets Copilot pick patterns. Reinforce by:
// Style: ... comment before a series of helpers.@version only on functional changes, not style edits.@deprecated tag explaining alternative and planned removal version.feat:, fix:, docs:, refactor:, test:, chore: prefix./**
* 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));
}
Always remember we are in ESM module with ts-jest.
So use jest.unstable_mockModule and not jest.mock.
Always use
npm run test:coverage -- yourTest.test.ts
Short, opinionated. If a rule isn’t helping, propose a PR to adjust.