oxc-project/oxc · warning

Unexpected empty {fn_kind} `{}`

Error message

Unexpected empty {fn_kind} `{}`

What it means

This diagnostic comes from the `no_empty_function` rule in oxlint. It reports a function with an empty body when the function has a name. The message names the function kind, such as function, method, or arrow function, plus the function name. The config option `allow` takes a list of kinds that may stay empty, for example `["arrowFunctions"]`, `["constructors"]`, or `["methods"]`; by default no kind is allowed.

Source

Thrown at crates/oxc_linter/src/rules/eslint/no_empty_function.rs:29

use oxc_diagnostics::OxcDiagnostic;
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);
        }

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Remove the function when nothing calls it.
  2. Give it a body, or `throw new Error('not implemented');` for stubs.
  3. Allow the empty kind in the rule config, for example `"no-empty-function": ["warn", { "allow": ["constructors"] }]`.
  4. Suppress once with `// oxlint-disable-next-line no-empty-function`.

Example fix

// before
class Connector {
  close() {}
}

// after
class Connector {
  close() {
    this.socket?.close();
  }
}
Defensive patterns

Strategy: validation

Validate before calling

// crude scan: named functions with empty bodies
const empty = /function\s+([A-Za-z_$][\w$]*)\s*\([^)]*\)\s*{\s*}/.exec(src);
if (empty) throw new Error('empty function: ' + empty[1]);

Prevention

When it happens

Trigger: A named function, method, getter, setter, or constructor whose body is `{}`: `function noop() {}` or `class A { connect() {} }`. The rule reports it with its kind and name.

Common situations: Interface stubs during scaffolding: `class Store { load() {} save() {} }`. A required callback that the developer had no use for. A refactor removes the body and leaves the shell behind.

Related errors


AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20). Data as JSON: /api/errors/9a5fc16cc3037cb1. Report an issue: GitHub.