oxc-project/oxc · error · OxcDiagnostic

Use an object instead of a `class` with only `static` member

Error message

Use an object instead of a `class` with only `static` members.

What it means

Raised by unicorn/no-static-only-class when a `class` declaration contains only static members (no instance state or prototype methods), making the class a namespace. The faulting input is the static-only class declaration at the labeled span.

Source

Thrown at crates/oxc_linter/src/rules/unicorn/no_static_only_class.rs:9

use oxc_ast::{AstKind, ast::ClassElement};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::{GetSpan, Span};

use crate::{AstNode, context::LintContext, rule::Rule};

fn no_static_only_class_diagnostic(span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn("Use an object instead of a `class` with only `static` members.")
        .with_help("Convert to an object instead of a class with only static members.")
        .with_label(span)
}

#[derive(Debug, Default, Clone)]
pub struct NoStaticOnlyClass;

declare_oxc_lint!(
    /// ### What it does
    ///
    /// Disallow `class` declarations that exclusively contain `static` members.
    ///
    /// ### Why is this bad?
    ///
    /// A `class` with only `static` members should just be defined as an object instead.
    ///
    /// ### Examples
    ///

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Convert the class to a plain object with the members as properties
  2. Use named exports of individual functions/constants instead of a container class
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/oxc_linter/src/rules/unicorn/no_static_only_class.rs:9 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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