{"record":{"id":"dee112ac8f50e71d","repo":"oxc-project/oxc","slug":"invalid-class-name-use-expected","errorCode":null,"errorMessage":"Invalid class name, use `{expected}`.","messagePattern":"Invalid class name, use `(.+?)`\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/unicorn/custom_error_definition.rs","lineNumber":16,"sourceCode":"use oxc_ast::{\n    AstKind,\n    ast::{\n        AssignmentTarget, Class, ClassElement, Expression, MethodDefinitionKind,\n        PropertyDefinition, Statement,\n    },\n    match_member_expression,\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::{GetSpan, Span};\n\nuse crate::{AstNode, ast_util, context::LintContext, rule::Rule};\n\nfn invalid_class_name_diagnostic(span: Span, expected: &str) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\"Invalid class name, use `{expected}`.\")).with_label(span)\n}\n\nfn missing_super_call_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Missing call to `super()` in constructor.\").with_label(span)\n}\n\nfn invalid_name_property_diagnostic(span: Span, name: &str) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\"The `name` property should be set to `{name}`.\")).with_label(span)\n}\n\nfn pass_message_to_super_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Pass the error message to `super()` instead of setting `this.message`.\")\n        .with_label(span)\n}\n\nfn invalid_export_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Exported error name should match error class\").with_label(span)\n}","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/unicorn/custom_error_definition.rs#L1-L34","documentation":"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'.`","triggerScenarios":"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.","commonSituations":"Domain error hierarchies written quickly (`class authError`); codebases extending library bases like `MyLibError`; enabling this pending unicorn rule during an error-handling cleanup.","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."],"exampleFix":"// before\nclass validationError extends Error {\n  constructor(message) {\n    super(message);\n    this.name = 'ValidationError';\n  }\n}\n// after\nclass ValidationError extends Error {\n  constructor(message) {\n    super(message);\n    this.name = 'ValidationError';\n  }\n}","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["oxlint","lint","unicorn","errors","naming","classes"],"backgroundTag":"custom-error-subclassing","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}