{"record":{"id":"11e5c9dfd405e0a9","repo":"oxc-project/oxc","slug":"default-parameters-should-be-last","errorCode":null,"errorMessage":"Default parameters should be last","messagePattern":"Default parameters should be last","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/default_param_last.rs","lineNumber":9,"sourceCode":"use oxc_ast::{AstKind, ast::FormalParameter, ast::Function};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::Span;\n\nuse crate::{AstNode, context::LintContext, rule::Rule};\n\nfn default_param_last_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Default parameters should be last\")\n        .with_help(\"Enforce default parameters to be last.\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct DefaultParamLast;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Requires default parameters in functions to be the last ones.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// Placing default parameters last allows function calls to omit optional trailing arguments,\n    /// which improves readability and consistency. This rule applies equally to JavaScript and\n    /// TypeScript functions.\n    ///","sourceCodeStart":1,"sourceCodeEnd":27,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/default_param_last.rs#L1-L27","documentation":"Oxlint's port of the ESLint rule default-param-last: parameters with default values must come after all required parameters. The rule visits FormalParameter lists of Function nodes (crates/oxc_linter/src/rules/eslint/default_param_last.rs:8) and flags a defaulted parameter that is followed by a non-defaulted one, since callers must then pass undefined explicitly or rely on confusing hole semantics.","triggerScenarios":"`function f(a = 1, b) {}`, `function f(a = 1, ...rest) {}`, and the same shape in methods, constructors, and setters.","commonSituations":"Adding a new required parameter to a legacy signature that already had defaults; parameter reordering during refactors; API evolution without an options object.","solutions":["Reorder so required parameters come first: `function f(b, a = 1)`.","If the trailing parameter must remain, give every preceding parameter a default as well.","Prefer an options object for growing signatures to avoid breaking call sites."],"exampleFix":"// before\nfunction create(type = 'div', children) {\n  /* ... */\n}\n\n// after\nfunction create(children, type = 'div') {\n  /* ... */\n}","handlingStrategy":"validation","validationCode":"// .oxlintrc.json\n{\n  \"rules\": {\n    \"default-param-last\": \"warn\"\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Add new required parameters before existing defaulted ones, or switch to an options object.","When a signature grows past ~3 params with defaults, refactor to a single options parameter.","Update all call sites when reordering parameters — the linter cannot catch those."],"tags":["eslint","oxlint","parameters","function-signature"],"backgroundTag":"default-parameter-not-last","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"}