getter-return
What it does
Section titled “What it does”Reports a getter written with get name() {} (in a class or an object literal) that does not return a value on every path: an empty body, a return; without a value, or an if without else that returns only in one branch. A getter that always throws is not reported, and neither is a get function given to Object.defineProperty.
Why it matters
Section titled “Why it matters”A property read calls the getter and takes its result, so a path without a value makes the property undefined, usually by a forgotten return rather than by intent.
To fix, return a value on every path.
Example
Section titled “Example”...function j() { try { a(); } finally { function k() { return 1; } } }...function m() { try { a(); } finally { m: { break m; } } }var o = { get a() {}, get b() { return; }, get c() { return 1; }, get d() { if (x) return 1; }, get e() { throw 1; } };class K { get a() {} static get b() { return 1 } get c() { while (true) {} } }function* p() {}...function* s() { yield 1; }...Configuration
Section titled “Configuration”js: lint: rules: getter-return: error # off, warn, error (default)Enabled by the presets: js/eslint-recommended, js/biome-recommended, js/oxlint.
Suppress one line with sudsy-disable-next-line getter-return in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools. full: Sudsy reports what the upstream rule reports; partial: only part of it, as the last column says.
| Tool | Rule | Match | What differs |
|---|---|---|---|
| eslint | getter-return |
partial | the getters of Object.defineProperty and Reflect.defineProperty descriptors are not checked |