deslop/unused-class-member

Flag a public/protected class method, property, or accessor that is declared but never referenced anywhere in the codebase.

  • Category: Dead Code
  • Severity: warn
  • Source: deslop-js
  • Framework: global
  • Enabled when: react-doctor deadCode analysis enabled (default true); whole-project scan only — skipped in --diff/--staged modes
  • Documentation: https://github.com/millionco/deslop-js

Validation prompt

Use this to decide whether a fired diagnostic is real or a false positive.

Fires from deslop's detectUnusedClassMembers when a non-constructor class member has no reference outside its own declaration, tagged with memberKind method/property/accessor and isStatic; reason reads "Class.member is declared but never referenced" (confidence high), or for an exported class "Class.member has no internal references; flagged at low confidence because Class is part of the public API surface" (confidence low). deslop already skips private/#-prefixed members, members carrying a decorator in its default decoratorAllowlist (Component, Injectable, Controller, Get, Post, Resolver, Query, etc.), members overridden by a subclass that extends this class, and a fixed React/Angular lifecycle list (render, componentDidMount, ngOnInit, canActivate, transform, validate, writeValue). False positive to SUPPRESS: the member is still reached invisibly to static analysis — invoked by name through a framework/DI container or a decorator OUTSIDE deslop's default decoratorAllowlist (e.g. @Cron, a custom DI/scheduler decorator), read dynamically via this[name] or bracket access, satisfies an interface the class implements (deslop's override index walks only extends heritage via ExtendsKeyword, never implements), is a route/event handler wired by string, or for a low-confidence exported-class hit is genuine public API consumed by downstream packages or tests outside the scanned graph.

Fix prompt

Use this once validation confirms the diagnostic is real.

Confirm the member is truly dead by searching for its name across the repo including string-keyed access (this["foo"]), template/decorator metadata, and interface implementors, then delete the whole method/property/accessor; if it only exists to satisfy an interface or abstract base, keep it but you can usually narrow or drop the now-orphan declaration on the contract side too. If it is intentionally retained for an external/framework caller deslop cannot see, either mark it private when access truly is internal-only, or add its decorator to the detector's decoratorAllowlist config field so future scans stay quiet (e.g. add "Cron" alongside the defaults). Removing unreferenced members shrinks the class surface and prevents stale logic from drifting. See https://www.typescriptlang.org/docs/handbook/2/classes.html#member-visibility