oxc-project/oxc · warning · OxcDiagnostic
Invalid class name, use `{expected}`.
Error message
Invalid class name, use `{expected}`. What it means
Diagnostic from oxlint's `unicorn/custom-error-definition` rule (registered under the `pending` category, so it must be enabled explicitly). When a class extends a statically-named error superclass — an identifier or member expression whose name is PascalCase segments ending in `Error`, e.g. `Error`, `TypeError`, `MyLib.NetworkError` — the subclass name must itself be the PascalCase form ending in `Error`. `get_class_name` uppercases the first letter and re-attaches a canonical `Error` suffix; any other spelling yields `Invalid class name, use '<Expected>Error'.`
Source
Thrown at crates/oxc_linter/src/rules/unicorn/custom_error_definition.rs:16
use oxc_ast::{
AstKind,
ast::{
AssignmentTarget, Class, ClassElement, Expression, MethodDefinitionKind,
PropertyDefinition, Statement,
},
match_member_expression,
};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::{GetSpan, Span};
use crate::{AstNode, ast_util, context::LintContext, rule::Rule};
fn invalid_class_name_diagnostic(span: Span, expected: &str) -> OxcDiagnostic {
OxcDiagnostic::warn(format!("Invalid class name, use `{expected}`.")).with_label(span)
}
fn missing_super_call_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Missing call to `super()` in constructor.").with_label(span)
}
fn invalid_name_property_diagnostic(span: Span, name: &str) -> OxcDiagnostic {
OxcDiagnostic::warn(format!("The `name` property should be set to `{name}`.")).with_label(span)
}
fn pass_message_to_super_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Pass the error message to `super()` instead of setting `this.message`.")
.with_label(span)
}
fn invalid_export_diagnostic(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Exported error name should match error class").with_label(span)
}View on GitHub (pinned to e1e7af627c)
Solutions
- Rename the class to the PascalCase name ending in `Error` shown in the message.
- Update all references and the `this.name` string to match the new class name.
- If the name is a public API you cannot change, disable the rule for that file or keep the rule off.
Example fix
// before
class validationError extends Error {
constructor(message) {
super(message);
this.name = 'ValidationError';
}
}
// after
class ValidationError extends Error {
constructor(message) {
super(message);
this.name = 'ValidationError';
}
} Defensive patterns
Strategy: validation
Prevention
- Name error subclasses in PascalCase ending with `Error` (e.g. `ValidationError`).
- Extend bases whose names themselves end in `Error` so the rule's superclass check matches.
- Keep the class name and the `this.name` string in sync when renaming.
When it happens
Trigger: A class with a valid error superclass whose declared name differs from its normalized form: `class customError extends Error`, `class validationError extends TypeError`, or a class missing the `Error` suffix entirely, with the message naming the expected replacement.
Common situations: Domain error hierarchies written quickly (`class authError`); codebases extending library bases like `MyLibError`; enabling this pending unicorn rule during an error-handling cleanup.
Related errors
- The `name` property should be set to `{name}`.
- Missing call to `super()` in constructor.
- The catch parameter {caught_ident:?} should be named {expect
- Pass a message to the {ctor_name:1} constructor.
- Error message should not be an empty string.
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/dee112ac8f50e71d.
Report an issue: GitHub.