{"record":{"id":"fdf1a40c2f1ce5fc","repo":"oxc-project/oxc","slug":"name-is-defined-but-never-used","errorCode":null,"errorMessage":"'{name}' is defined but never used.","messagePattern":"'(.+?)' is defined but never used\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/no_unused_private_class_members.rs","lineNumber":12,"sourceCode":"use itertools::Itertools;\nuse oxc_ast::{AstKind, ast::AssignmentOperator};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_semantic::{AstNode, NodeId, Semantic};\nuse oxc_span::{GetSpan, Span};\nuse oxc_syntax::class::ElementKind;\n\nuse crate::{context::LintContext, rule::Rule};\n\nfn no_unused_private_class_members_diagnostic(name: &str, span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\"'{name}' is defined but never used.\"))\n        .with_help(\"Remove the declaration or use it in the code.\")\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct NoUnusedPrivateClassMembers;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Disallow unused private class members.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// Private class members that are declared and not used anywhere in the code are most likely an error due to incomplete refactoring. Such class members take up space in the code and can lead to confusion by readers.\n    ///\n    /// ### Examples\n    ///","sourceCodeStart":1,"sourceCodeEnd":30,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/no_unused_private_class_members.rs#L1-L30","documentation":"Diagnostic from oxlint's no-unused-private-class-members rule. A #private field or method is declared but never referenced as this.#name anywhere, so it is dead code; very often the usage exists but is missing the # prefix (a typo that silently reads a public/undefined property instead).","triggerScenarios":"class C { #secret = 1; read() { return this.secret; } } (forgot the #); a #cache field never touched; renaming a member but not all use sites.","commonSituations":"Refactor renames where the # is dropped; speculative memoization fields kept 'for later'; privates whose only consumer was removed.","solutions":["If the member is a typo victim, fix the use sites to include the #: this.#secret.","Otherwise remove the unused private member entirely.","Re-add the member only when a real consumer exists, instead of keeping dead state."],"exampleFix":"// before\nclass C {\n  #secret = 1;\n  read() { return this.secret; }\n}\n// after\nclass C {\n  #secret = 1;\n  read() { return this.#secret; }\n}","handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["After renaming a private member, grep for both this.#name and this.name to catch dropped '#' prefixes.","Delete speculative private fields; add them when a real consumer exists.","Keep the rule enabled so unused privates surface at lint time rather than review time."],"tags":["eslint","oxlint","classes","private-fields","dead-code"],"backgroundTag":"unused-private-class-member","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}