oxc-project/oxc · warning · OxcDiagnostic

Default parameters should be last

Error message

Default parameters should be last

What it means

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.

Source

Thrown at crates/oxc_linter/src/rules/eslint/default_param_last.rs:9

use oxc_ast::{AstKind, ast::FormalParameter, ast::Function};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::Span;

use crate::{AstNode, context::LintContext, rule::Rule};

fn default_param_last_diagnostic(span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn("Default parameters should be last")
        .with_help("Enforce default parameters to be last.")
        .with_label(span)
}

#[derive(Debug, Default, Clone)]
pub struct DefaultParamLast;

declare_oxc_lint!(
    /// ### What it does
    ///
    /// Requires default parameters in functions to be the last ones.
    ///
    /// ### Why is this bad?
    ///
    /// Placing default parameters last allows function calls to omit optional trailing arguments,
    /// which improves readability and consistency. This rule applies equally to JavaScript and
    /// TypeScript functions.
    ///

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Reorder so required parameters come first: `function f(b, a = 1)`.
  2. If the trailing parameter must remain, give every preceding parameter a default as well.
  3. Prefer an options object for growing signatures to avoid breaking call sites.

Example fix

// before
function create(type = 'div', children) {
  /* ... */
}

// after
function create(children, type = 'div') {
  /* ... */
}
Defensive patterns

Strategy: validation

Validate before calling

// .oxlintrc.json
{
  "rules": {
    "default-param-last": "warn"
  }
}

Prevention

When it happens

Trigger: `function f(a = 1, b) {}`, `function f(a = 1, ...rest) {}`, and the same shape in methods, constructors, and setters.

Common situations: Adding a new required parameter to a legacy signature that already had defaults; parameter reordering during refactors; API evolution without an options object.

Related errors


AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20). Data as JSON: /api/errors/11e5c9dfd405e0a9. Report an issue: GitHub.