oxc-project/oxc · warning · OxcDiagnostic

Function name `{func_name}` should match variable name `{nam

Error message

Function name `{func_name}` should match variable name `{name}`.

What it means

The 'always + variable' arm of oxlint's func-name-matching port (crates/oxc_linter/src/rules/eslint/func_name_matching.rs:46). In the default mode `always`, a named function expression assigned to a variable must share the variable's name: `const foo = function bar() {}` is reported because `bar` differs from `foo`. The diagnostic labels the expression span and suggests renaming one side.

Source

Thrown at crates/oxc_linter/src/rules/eslint/func_name_matching.rs:46

    mode: FuncNameMatchingMode,
    span: Span,
) -> OxcDiagnostic {
    let msg = match (mode, is_property) {
        (FuncNameMatchingMode::Always, true) => {
            format!("Function name `{func_name}` should match property name `{name}`.")
        }
        (FuncNameMatchingMode::Always, false) => {
            format!("Function name `{func_name}` should match variable name `{name}`.")
        }
        (FuncNameMatchingMode::Never, true) => {
            format!("Function name `{func_name}` should not match property name `{name}`.")
        }
        (FuncNameMatchingMode::Never, false) => {
            format!("Function name `{func_name}` should not match variable name `{name}`.")
        }
    };

    OxcDiagnostic::warn(msg)
        .with_help("Rename the function or the variable/property so the names satisfy this rule.")
        .with_label(span)
}

#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "kebab-case")]
enum FuncNameMatchingMode {
    #[default]
    Always,
    Never,
}

#[derive(Debug, Default, Clone, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
struct FuncNameMatchingConfig {
    #[serde(default)]
    /// If `considerPropertyDescriptor` is set to `true`, the check will take into account the use of `Object.create`, `Object.defineProperty`, `Object.defineProperties`, and `Reflect.defineProperty`.
    consider_property_descriptor: bool,

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Rename the function expression to equal the variable name.
  2. Use a plain function declaration `function format(x)` instead of an assigned expression.
  3. Drop the name entirely if it is not needed for recursion.
  4. Switch the mode to `never` if mismatched names are your convention.

Example fix

// before
const format = function formatValue(x) {
  return String(x);
};

// after
function format(x) {
  return String(x);
}
Defensive patterns

Strategy: validation

Validate before calling

// .oxlintrc.json
{
  "rules": {
    "func-name-matching": ["warn", "always"]
  }
}

Prevention

When it happens

Trigger: `const format = function formatValue(x) { ... }` — any named function expression whose name differs from its assignee under mode `always`.

Common situations: Implementation-detail names kept for stack traces; renaming variables during refactor while the function name lags; module-pattern code.

Related errors


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