oxc-project/oxc · warning
Unexpected empty function
Error message
Unexpected empty function
What it means
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.
Source
Thrown at crates/oxc_linter/src/rules/eslint/no_empty_function.rs:30
use oxc_macros::declare_oxc_lint;
use oxc_span::Span;
use schemars::JsonSchema;
use serde::Deserialize;
use crate::{
AstNode,
context::LintContext,
rule::{DefaultRuleConfig, Rule},
};
fn no_empty_function_diagnostic<S: AsRef<str>>(
span: Span,
fn_kind: &str,
fn_name: Option<S>,
) -> OxcDiagnostic {
let message = match fn_name {
Some(name) => Cow::Owned(format!("Unexpected empty {fn_kind} `{}`", name.as_ref())),
None => Cow::Borrowed("Unexpected empty function"),
};
OxcDiagnostic::warn(message)
.with_help(format!("Consider removing this {fn_kind} or adding logic to it."))
.with_label(span)
}
#[derive(Debug, Default, Clone)]
pub struct NoEmptyFunction {
allow: Allowed,
}
impl From<NoEmptyFunctionConfig> for NoEmptyFunction {
fn from(config: NoEmptyFunctionConfig) -> Self {
let mut flags = Allowed::None;
for kind in &config.allow {
flags |= Allowed::from(*kind);
}
Self { allow: flags }View on GitHub (pinned to e1e7af627c)
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.
Example fix
// before
subscribe('tick', function () {});
// after
subscribe('tick', () => {
logger.debug('tick');
}); Defensive patterns
Strategy: validation
Validate before calling
// find anonymous empty functions before lint
if (/function\s*\([^)]*\)\s*{\s*}/.test(src)) throw new Error('anonymous empty function found'); Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Unexpected empty {fn_kind} `{}`
- The function binding is unnecessary.
- `debugger` statement is not allowed
- Variables should not be deleted
- A regular expression literal can be confused with '/='.
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/5c3537e4eb37b638.
Report an issue: GitHub.