{"record":{"id":"5c3537e4eb37b638","repo":"oxc-project/oxc","slug":"unexpected-empty-function","errorCode":null,"errorMessage":"Unexpected empty function","messagePattern":"Unexpected empty function","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/no_empty_function.rs","lineNumber":30,"sourceCode":"use oxc_macros::declare_oxc_lint;\nuse oxc_span::Span;\nuse schemars::JsonSchema;\nuse serde::Deserialize;\n\nuse crate::{\n    AstNode,\n    context::LintContext,\n    rule::{DefaultRuleConfig, Rule},\n};\n\nfn no_empty_function_diagnostic<S: AsRef<str>>(\n    span: Span,\n    fn_kind: &str,\n    fn_name: Option<S>,\n) -> OxcDiagnostic {\n    let message = match fn_name {\n        Some(name) => Cow::Owned(format!(\"Unexpected empty {fn_kind} `{}`\", name.as_ref())),\n        None => Cow::Borrowed(\"Unexpected empty function\"),\n    };\n    OxcDiagnostic::warn(message)\n        .with_help(format!(\"Consider removing this {fn_kind} or adding logic to it.\"))\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct NoEmptyFunction {\n    allow: Allowed,\n}\n\nimpl From<NoEmptyFunctionConfig> for NoEmptyFunction {\n    fn from(config: NoEmptyFunctionConfig) -> Self {\n        let mut flags = Allowed::None;\n        for kind in &config.allow {\n            flags |= Allowed::from(*kind);\n        }\n        Self { allow: flags }","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/no_empty_function.rs#L12-L48","documentation":"This diagnostic comes from the same `no_empty_function` rule. When the empty function has no printable name, the rule falls back to the plain message `Unexpected empty function`. Everything else matches the named case: an empty body and the same `allow` list in the config. Anonymous functions passed as arguments are the usual source.","triggerScenarios":"An anonymous empty function expression in argument position: `subscribe('tick', function () {});` or `setTimeout(function () {}, 100)`. The name lookup returns `None`, so the fallback message is used.","commonSituations":"Callback stubs passed to map, filter, or event APIs. A third-party API requires a callback but the code has no use for it. Prototypes with arrow stubs left in place.","solutions":["Remove the call when the empty callback has no effect, or give the callback a body.","Pass one named `noop` utility from a shared module and allow that pattern in the config.","Allow anonymous kinds with the `allow` option when stubs are common in the codebase."],"exampleFix":"// before\nsubscribe('tick', function () {});\n\n// after\nsubscribe('tick', () => {\n  logger.debug('tick');\n});","handlingStrategy":"validation","validationCode":"// find anonymous empty functions before lint\nif (/function\\s*\\([^)]*\\)\\s*{\\s*}/.test(src)) throw new Error('anonymous empty function found');","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Omit the callback argument when the API makes it optional.","Keep one shared `noop` function and allow that pattern in the config.","Run oxlint on save so stubs are flagged at creation."],"tags":["javascript","eslint","lint","functions","stub-code"],"backgroundTag":"lint-empty-function","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"}