{"record":{"id":"012aacd53950fd9b","repo":"oxc-project/oxc","slug":"this-function-does-not-use-any-variables-from-its","errorCode":null,"errorMessage":"This function does not use any variables from its parent scope","messagePattern":"This function does not use any variables from its parent scope","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/unicorn/consistent_function_scoping.rs","lineNumber":30,"sourceCode":"    ast_util::{get_function_like_declaration, is_node_call_like_argument, outermost_paren_parent},\n    context::LintContext,\n    rule::{DefaultRuleConfig, Rule},\n    utils::is_react_hook,\n};\n\nfn consistent_function_scoping(\n    fn_span: Span,\n    parent_scope_span: Option<Span>,\n    parent_scope_kind: Option<&'static str>,\n    function_name: Option<&str>,\n) -> OxcDiagnostic {\n    let function_label = if let Some(name) = function_name {\n        format!(\"Function `{name}` does not capture any variables from its parent scope\")\n    } else {\n        \"This function does not use any variables from its parent scope\".into()\n    };\n\n    let d = OxcDiagnostic::warn(function_label).with_help(match function_name {\n        Some(name) => {\n            format!(\"Move `{name}` to the outer scope to avoid recreating it on every call.\")\n        }\n        None => {\n            \"Move this function to the outer scope to avoid recreating it on every call.\".into()\n        }\n    });\n\n    match parent_scope_span {\n        Some(parent) => d.with_labels([\n            parent.label(\"Outer scope where this function is defined\"),\n            fn_span.primary_label(if let Some(parent_scope_kind) = parent_scope_kind {\n                format!(\n                    \"This function does not use any variables from the parent {parent_scope_kind}\"\n                )\n            } else {\n                \"This function does not use any variables from here\".into()\n            }),","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/unicorn/consistent_function_scoping.rs#L12-L48","documentation":"Diagnostic from oxlint's `unicorn/consistent-function-scoping` rule, anonymous variant: the flagged function has no name, so the message reads 'This function does not use any variables from its parent scope'. The function is defined in an inner scope yet captures nothing from it, so it can be hoisted to module scope to avoid being recreated on every call. Help text and dual labels (outer scope + function) are the same as the named variant.","triggerScenarios":"Anonymous function expressions and arrow functions assigned or passed inline whose bodies reference only their own parameters and globals, e.g. `const doBar = bar => bar === 'bar';` inside `doFoo`, or `arr.map(x => x * 2)` inside a frequently-called function (subject to call-argument exemptions in the rule).","commonSituations":"Arrow helpers inside components and reducers; callback factories inside loops; enabling unicorn presets on callback-heavy code and getting many findings at once.","solutions":["Hoist the anonymous function to module scope and give it a name.","If it genuinely belongs locally, reference an outer variable or pass state via parameters so the intent is explicit.","Set `checkArrowFunctions: false` if arrow checking is too noisy for your style.","Suppress intentional cases with an inline disable comment."],"exampleFix":"// before\nfunction makeGreeter() {\n  return name => `Hello, ${name}`;\n}\n// after\nconst greet = name => `Hello, ${name}`;\n\nfunction makeGreeter() {\n  return greet;\n}","handlingStrategy":"validation","validationCode":"// .oxlintrc.json — silence arrows if only named functions should be checked\n{\n  \"rules\": {\n    \"unicorn/consistent-function-scoping\": [\"warn\", { \"checkArrowFunctions\": false }]\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Name and hoist anonymous helpers that do not close over anything.","Avoid defining callback factories inside frequently-called functions.","Treat repeated identical arrow definitions inside a function as a hoisting signal during review."],"tags":["oxlint","lint","unicorn","scoping","functions","performance"],"backgroundTag":"unnecessary-closures","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}