oxc-project/oxc · warning · OxcDiagnostic
Function name `{func_name}` should not match variable name `
Error message
Function name `{func_name}` should not match variable name `{name}`. What it means
The 'never + variable' arm of oxlint's func-name-matching port (crates/oxc_linter/src/rules/eslint/func_name_matching.rs:46). Under mode `never`, a named function expression whose name equals the variable it is assigned to is reported: `const foo = function foo() {}` duplicates the name that assignment already provides.
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
- Drop the function expression's name (make it anonymous or an arrow function).
- Use a function declaration if a name is required.
- If you want names everywhere, configure the mode as `always` instead.
Example fix
// before
const fetchUser = function fetchUser(id) { /* ... */ };
// after
const fetchUser = (id) => { /* ... */ }; Defensive patterns
Strategy: validation
Validate before calling
// .oxlintrc.json
{
"rules": {
"func-name-matching": ["warn", "never"]
}
} Prevention
- Use anonymous or arrow function expressions under `never` mode.
- Use declarations when a name is required for recursion or stack clarity.
- Keep the mode in sync with the team's stack-trace policy.
When it happens
Trigger: `const fetchUser = function fetchUser() {}` with the rule configured as ["warn", "never"].
Common situations: Names duplicated for stack-trace clarity inside a `never`-mode codebase; ESLint parity configs where the mode was inverted during migration.
Related errors
- Function name `{func_name}` should not match property name `
- Function name `{func_name}` should match property name `{nam
- Function name `{func_name}` should match variable name `{nam
- Unexpected named {function_name}.
- Expected a function {style}.
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/f4a10380b1c85e6c.
Report an issue: GitHub.