{"record":{"id":"14a0daafc1a54e85","repo":"oxc-project/oxc","slug":"unexpected-named-function-name","errorCode":null,"errorMessage":"Unexpected named {function_name}.","messagePattern":"Unexpected named (.+?)\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/func_names.rs","lineNumber":29,"sourceCode":"use oxc_macros::declare_oxc_lint;\nuse oxc_semantic::NodeId;\nuse oxc_span::{GetSpan, Span};\nuse oxc_str::Ident;\nuse oxc_syntax::{identifier::is_identifier_name, keyword::is_reserved_keyword_or_global_object};\n\nuse schemars::JsonSchema;\nuse serde::Deserialize;\n\nuse crate::{\n    AstNode,\n    ast_util::get_function_name_with_kind,\n    context::LintContext,\n    fixer::{RuleFix, RuleFixer},\n    rule::{Rule, TupleRuleConfig},\n};\n\nfn named_diagnostic(function_name: &str, span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\"Unexpected named {function_name}.\"))\n        .with_label(span)\n        .with_help(\"Remove the name on this function expression.\")\n}\n\nfn unnamed_diagnostic(inferred_name_or_description: &str, span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\"Unexpected unnamed {inferred_name_or_description}.\"))\n        .with_label(span)\n        .with_help(\"Consider giving this function expression a name.\")\n}\n\n#[derive(Debug, Default, Clone, Copy, PartialEq, JsonSchema, Deserialize)]\n#[serde(rename_all = \"kebab-case\")]\nenum FuncNamesConfigType {\n    /// Requires all function expressions to have a name.\n    #[default]\n    Always,\n    /// Requires a name only if one is not automatically inferred.\n    AsNeeded,","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/func_names.rs#L11-L47","documentation":"One of the two diagnostics in oxlint's func-names rule (crates/oxc_linter/src/rules/eslint/func_names.rs:28). named_diagnostic fires when a function expression carries a name the rule considers unnecessary: with the `as-needed` option, names are only permitted when actually needed (e.g. the body references itself), so an unneeded name is reported as 'Unexpected named function expression.' The name/kind in the message comes from get_function_name_with_kind. The complementary unnamed_diagnostic fires under the `always` option (the default) for nameless expressions.","triggerScenarios":"Rule configured with \"as-needed\" and code like `const parse = function parseJson(t) { return JSON.parse(t); }` where the body never references parseJson, so the name is inferable and not needed.","commonSituations":"Migrating configs that set as-needed; teams split between keep-names-for-stack-traces and anonymous styles; names added only for debugging that survive into commits.","solutions":["Remove the unneeded name: `const parse = function (t)` or an arrow function — the binding still names it.","Keep names only where the body references them (recursion) or an API requires named handlers.","If you want names everywhere for stack traces, set the option back to `always` or disable the rule."],"exampleFix":"// before (option: as-needed)\nconst parse = function parseJson(text) {\n  return JSON.parse(text);\n};\n\n// after\nconst parse = (text) => JSON.parse(text);","handlingStrategy":"validation","validationCode":"// .oxlintrc.json — choose \"always\" if names aid your stack traces\n{\n  \"rules\": {\n    \"func-names\": [\"warn\", \"as-needed\"]\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Under as-needed, keep names only where the body references itself.","Remember the binding still names anonymous expressions (const parse = () => {} is named parse).","Set \"always\" when debugging production stack traces matters more than brevity."],"tags":["eslint","oxlint","naming","function-expression","anonymous-function"],"backgroundTag":"unnecessary-function-name","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"}