A getter has no return, so reading the property gives undefined
What it finds
get name() { this._name; }: a getter that never returns a value gives undefined to everyone who reads the property, which is never what a getter is for. Usually return was left out.
A getter is reported when its body, outside nested functions, has no return at all; a bare return; says that undefined is meant. Getters that throw, as an abstract getter that must be overridden does, or call a function named for not returning, are left alone.
From the rule's source, getter_without_return.rs.
class User { private first = ""; get name() {tx0 reports: this getter never returns a value this.first.trim(); } get initial() { return this.first[0]; } get abstractValue(): number { throw new Error("not implemented"); }}const view = { get label() {tx0 reports: this getter never returns a value const make = () => { return "x"; }; },}; Turn it on, off or suppress it
The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:
[rules]
"tx0/ts:getter-without-return" = "off"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:getter-without-return] reason="..."tx0 explain tx0/ts:getter-without-return shows the same in the terminal. Found a false positive? Report it.