derived-lookup-map
a constant that merely uses the union kept in the `const` object's file
Agent checkadvisory by defaultbasecode
The argument
Derived Lookup Maps May Co-Locate
A lookup map keyed by the union (Record<Action, …>) may live in the same file as the const object — the two are tautologically coupled, so every change to one changes the other.
export const LogLevel = {
Debug: 'debug',
Info: 'info',
Error: 'error',
} as const;
export type LogLevel = (typeof LogLevel)[keyof typeof LogLevel];
export const logLevelLabels: Record<LogLevel, string> = {
[LogLevel.Debug]: 'Debug',
[LogLevel.Info]: 'Info',
[LogLevel.Error]: 'Error',
};
An unrelated constant that merely uses the union goes in constants/ as usual.
The proof
failsrc/common/constants/LogLevel.ts
export const LogLevel = {
Debug: 'debug',
Info: 'info',
Error: 'error',
} as const;
export type LogLevel = (typeof LogLevel)[keyof typeof LogLevel];
// Not keyed by the union — it merely uses it, so it is an unrelated constant
// riding along in this file instead of living in `constants/` on its own.
export const defaultLogLevel: LogLevel = LogLevel.Info;
passsrc/common/constants/LogLevel.ts
export const LogLevel = {
Debug: 'debug',
Info: 'info',
Error: 'error',
} as const;
export type LogLevel = (typeof LogLevel)[keyof typeof LogLevel];
// Keyed by the union, so the two are tautologically coupled: every change to
// one is a change to the other.
export const logLevelLabels: Record<LogLevel, string> = {
[LogLevel.Debug]: 'Debug',
[LogLevel.Info]: 'Info',
[LogLevel.Error]: 'Error',
};
Turn it down
Both lines go in your lightsout.config.json.
"standards-checks": { "derived-lookup-map": "advisory" }"standards-checks": { "derived-lookup-map": "off" }