An enum member is initialized with a computed value instead of a literal
What it finds
An enum whose members are literals can be inlined, compared exhaustively and understood without running code. A member initialized with a call or another expression is evaluated at run time, prevents const enum, and its value is not visible where the enum is declared.
Reported are enum members initialized with something other than a number or string literal, a negated number, or a reference to another member of the same enum.
From the rule's source, computed_enum_member.rs.
declare function nextId(): number;export enum Code { Ok = 0, Next = nextId(),tx0 reports: this enum member is computed when the code runs Flag = 1 << 2,} Turn it on, off or suppress it
The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/ts:computed-enum-member" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/ts:computed-enum-member] reason="..."tx0 explain tx0/ts:computed-enum-member shows the same in the terminal. Found a false positive? Report it.