{"record":{"id":"23ffd42f61e8a52a","repo":"oxc-project/oxc","slug":"prefer-default-parameters-over-reassignment-for","errorCode":null,"errorMessage":"Prefer default parameters over reassignment for '{name}'.","messagePattern":"Prefer default parameters over reassignment for '(.+?)'\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/unicorn/prefer_default_parameters.rs","lineNumber":16,"sourceCode":"use oxc_ast::{\n    AstKind,\n    ast::{\n        AssignmentOperator, AssignmentTarget, BindingPattern, Expression, FormalParameter,\n        LogicalOperator, MethodDefinitionKind, PropertyKind, Statement,\n    },\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::{GetSpan, Span};\nuse oxc_syntax::node::NodeId;\n\nuse crate::{AstNode, context::LintContext, rule::Rule};\n\nfn prefer_default_parameters_diagnostic(span: Span, name: &str) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\"Prefer default parameters over reassignment for '{name}'.\"))\n        .with_help(\"Replace the reassignment with a default parameter.\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct PreferDefaultParameters;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Instead of reassigning a function parameter, default parameters should be used. The `foo = foo || 123` statement evaluates to `123` when `foo` is falsy, possibly leading to confusing behavior, whereas default parameters only apply when passed an `undefined` value.\n    /// This rule only reports reassignments to literal values.\n    ///\n    /// You should disable this rule if you want your functions to deal with `null` and other falsy values the same way as `undefined`.\n    /// Default parameters are exclusively applied [when `undefined` is received.](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Default_parameters#passing_undefined_vs._other_falsy_values).\n    /// However, we recommend [moving away from `null`](https://github.com/sindresorhus/meta/discussions/7).\n    ///\n    /// ### Why is this bad?","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/unicorn/prefer_default_parameters.rs#L1-L34","documentation":"Diagnostic from the unicorn/prefer-default-parameters lint rule. It fires when a function body immediately reassigns a formal parameter with an expression like `name = name || 'default'` or `if (name === undefined) name = ...`. The parameter name in the message is the variable being reassigned. ES2015 default parameters (`function f(name = 'default')`) express the same intent in the signature and avoid a body-level mutation. It is a lint warning, not a runtime error.","triggerScenarios":"Thrown at crates/oxc_linter/src/rules/unicorn/prefer_default_parameters.rs:16 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Move the fallback value into the parameter list: `function f(name = 'default')`","Remove the reassignment statement from the function body","Use a nullish-coalescing default in the signature (`name = fallback`) when `null` should also trigger the default"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}