{"record":{"id":"0f4e547daa27cedb","repo":"oxc-project/oxc","slug":"do-not-use-useless-undefined","errorCode":null,"errorMessage":"Do not use useless `undefined`.","messagePattern":"Do not use useless `undefined`\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/unicorn/no_useless_undefined.rs","lineNumber":19,"sourceCode":"use oxc_ast::{\n    AstKind,\n    ast::{Argument, CallExpression, Expression, VariableDeclarationKind},\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::{GetSpan, Span};\nuse schemars::JsonSchema;\nuse serde::Deserialize;\n\nuse crate::{\n    AstNode,\n    ast_util::{is_method_call, outermost_paren_parent},\n    context::LintContext,\n    rule::{DefaultRuleConfig, Rule},\n};\n\nfn warn() -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Do not use useless `undefined`.\")\n        .with_help(\"Consider removing `undefined` or using `null` instead.\")\n}\n\nfn no_useless_undefined_diagnostic(span: Span) -> OxcDiagnostic {\n    warn().with_label(span)\n}\n\nfn no_useless_undefined_diagnostic_spans(spans: Vec<Span>) -> OxcDiagnostic {\n    warn().with_labels(spans)\n}\n\n#[derive(Debug, Clone, JsonSchema, Deserialize)]\n#[serde(rename_all = \"camelCase\", default, deny_unknown_fields)]\npub struct NoUselessUndefined {\n    /// Whether to check for useless `undefined` in function call arguments.\n    check_arguments: bool,\n    /// Whether to check for useless `undefined` in arrow function bodies.\n    check_arrow_function_body: bool,","sourceCodeStart":1,"sourceCodeEnd":37,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/unicorn/no_useless_undefined.rs#L1-L37","documentation":"Diagnostic from the oxlint rule `unicorn/no-useless-undefined` (pedantic, autofixable). It fires where `undefined` is the implicit default anyway: `return undefined;`, `yield undefined;`, an arrow's concise body `() => undefined`, `let`/`var` initialization `let foo = undefined;`, destructuring defaults `const {foo = undefined} = {}`, parameter defaults `function f(bar = undefined) {}`, and trailing `undefined` call arguments `foo(bar, undefined)`. Exceptions: TypeScript functions with an explicit return type, `const` declarations, `yield* undefined`, parameter defaults after an optional parameter, and calls to a large ignore list (`toEqual`, `toBe`, `toHaveBeenCalledWith`, `push`, `set*` names, `createContext`, `ref`, `bind`, etc.) where `undefined` is a meaningful argument.","triggerScenarios":"`function foo() { return undefined; }`, `function* f() { yield undefined; }`, `const noop = () => undefined;`, `let a = undefined;`, `const {foo = undefined} = {};`, `function foo([bar = undefined] = []) {}`, `foo(bar, undefined, undefined);` (only the trailing run is removed). Options `checkArguments` and `checkArrowFunctionBody` (both default `true`) disable the argument and arrow-body checks respectively.","commonSituations":"Verbose code from developers who want explicitness about returning nothing, and refactors from APIs where `undefined` was a real value. Conflicts with `eslint/array-callback-return` and `getter-return` unless `allowImplicit` is set; test frameworks like Jest/Vue (`toEqual(undefined)`, `ref(undefined)`) are pre-exempted via the ignore list.","solutions":["Remove the `undefined`: `let foo = undefined;` -> `let foo;`, `() => undefined` -> `() => {}`, `return undefined;` -> `return;`.","Run `oxlint --fix` to apply the rule's autofixes.","If you need an explicit 'no value' sentinel, use `null` instead, as the help suggests.","Configure the rule: `{ \"checkArguments\": false }` for calls like `run(undefined)` against optional parameters, `{ \"checkArrowFunctionBody\": false }` for arrow bodies.","For TypeScript, adding an explicit return type annotation (e.g. `(): undefined`) exempts the function."],"exampleFix":"// before\nlet foo = undefined;\nconst noop = () => undefined;\nfunction f(bar = undefined) {}\n\n// after\nlet foo;\nconst noop = () => {};\nfunction f(bar) {}","handlingStrategy":"validation","validationCode":"# detect likely-useless undefined usages\nrg -n --type js '(?:return|yield)\\s+undefined\\s*;|=>\\s*undefined\\s*;|(?:let|var)\\s+\\w+\\s*=\\s*undefined|=\\s*undefined\\s*[,}]|,\\s*undefined\\s*[,)]' src/","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Rely on implicit defaults: bare `return;`, `let x;`, `function f(a) {}`.","Use `null` when an explicit sentinel value is required; reserve `undefined` for genuine values (test matchers, `createContext`, `ref`).","Configure `checkArguments: false` if your API relies on optional-parameter calls with `undefined`.","Set `allowImplicit` on eslint array-callback-return/getter-return when running both linters."],"tags":["lint","oxlint","unicorn","undefined","dead-code","pedantic","typescript"],"backgroundTag":"useless-undefined","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}