{"record":{"id":"28275e30fa071104","repo":"oxc-project/oxc","slug":"expected-to-always-return-a-value-in-getter","errorCode":null,"errorMessage":"Expected to always return a value in getter.","messagePattern":"Expected to always return a value in getter\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/eslint/getter_return.rs","lineNumber":29,"sourceCode":"        Direction,\n        visit::{Control, DfsEvent, set_depth_first_search},\n    },\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::Span;\nuse schemars::JsonSchema;\nuse serde::Deserialize;\nuse serde_json::Value;\n\nuse crate::{\n    AstNode,\n    context::{ContextHost, LintContext},\n    rule::{DefaultRuleConfig, Rule},\n};\n\nfn getter_return_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Expected to always return a value in getter.\")\n        .with_help(\"Return a value from all code paths in getter.\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone, JsonSchema, Deserialize)]\n#[serde(rename_all = \"camelCase\", default, deny_unknown_fields)]\npub struct GetterReturn {\n    /// When set to `true`, allows getters to implicitly return `undefined` with a `return` statement containing no expression.\n    pub allow_implicit: bool,\n}\n\nconst METHODS_TO_WATCH_FOR: [(&str, &str); 4] = [\n    (\"Object\", \"defineProperty\"),\n    (\"Reflect\", \"defineProperty\"),\n    (\"Object\", \"create\"),\n    (\"Object\", \"defineProperties\"),\n];\n","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/getter_return.rs#L11-L47","documentation":"Oxlint's port of the ESLint rule getter-return (crates/oxc_linter/src/rules/eslint/getter_return.rs:28): a getter must return a value on every code path. The rule checks named getters plus getters passed to a watchlist of four defineProperty-style APIs (METHODS_TO_WATCH_FOR in this file). The config carries `allowImplicit: bool` — when true, a bare `return;` counts as returning undefined; by default it does not, and a getter that can fall through without an expression is reported.","triggerScenarios":"A getter with a branch that falls through (`get x() { if (c) return v; }`), or a getter containing only `return;` while allowImplicit is false. Also fires for `Object.defineProperty(obj, 'x', { get() { ... } })` shapes.","commonSituations":"Adding an early guard clause to a getter and forgetting the fallthrough return; ESLint configs where allowImplicit was enabled but not carried to oxlint; generated getters.","solutions":["Return a value on every path: add a final `return fallback;` after the branches.","If undefined is intended, return it explicitly or set \"allowImplicit\": true in .oxlintrc.json.","If the member performs work rather than exposing state, convert the getter to a method."],"exampleFix":"// before\nget label() {\n  if (this.raw) return this.raw.trim();\n}\n\n// after\nget label() {\n  if (this.raw) return this.raw.trim();\n  return '';\n}","handlingStrategy":"validation","validationCode":"// .oxlintrc.json — permit bare `return;` if undefined is intentional\n{\n  \"rules\": {\n    \"getter-return\": [\"error\", { \"allowImplicit\": false }]\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["End every getter with an unconditional `return` of a value.","Carry over ESLint's allowImplicit setting when migrating configs.","Prefer methods over getters for anything that performs work rather than exposing state."],"tags":["eslint","oxlint","getter","return-value","possible-error"],"backgroundTag":"getter-missing-return-value","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}