[Angular][Dead-code] Course class has 8 declared-but-never-assigned/read private fields (classes/course.ts) #687

Open
opened 2026-07-17 22:35:49 +00:00 by spikerj · 1 comment
Owner

Context

Found while triaging SonarQube S2933 (readonly) on projects/spikersoft/src/app/_components/classes/course.ts. SonarQube flags all 13 fields as "never reassigned → mark readonly", but on inspection 8 of them are never assigned or read anywhere in the class (it's a self-contained 43-line class with only private members, so there is no external access path):

  • description: string
  • audience: Array<string>
  • duration: string
  • format: Array<string>
  • assessment: Array<string>
  • certification: string
  • objectives: Array<string>
  • acknowledgements: Array<string>

The constructor only assigns courseCode, title, credits, prerequisites, enrolledStudents (the 5 real fields, each used by a method). The 8 above are declared with a type but no initializer, no constructor assignment, and no reader — under the workspace's strict:false they don't even trip strictPropertyInitialization, so they've sat silently as undefined.

Why not just mark them readonly

That's what a naive S2933 fix would do, but marking dead fields readonly papers over the real problem. This looks like an aspirational data model someone stubbed out and never wired up.

Fix options (needs a human decision)

  1. Delete the 8 fields if Course is meant to be the lightweight enroll/prereq class it currently behaves as — (recommended; simplest, and Course's only live behavior is enrollment + prerequisites), or
  2. Wire them up — add them to the constructor / a builder and the consumers that should populate course metadata, if the richer model was the intent.

Low priority / tech-debt. Filed so the S2933 sweep can skip this file cleanly rather than adding misleading readonly to dead members.

## Context Found while triaging SonarQube S2933 (readonly) on `projects/spikersoft/src/app/_components/classes/course.ts`. SonarQube flags all 13 fields as "never reassigned → mark readonly", but on inspection 8 of them are **never assigned or read anywhere** in the class (it's a self-contained 43-line class with only `private` members, so there is no external access path): - `description: string` - `audience: Array<string>` - `duration: string` - `format: Array<string>` - `assessment: Array<string>` - `certification: string` - `objectives: Array<string>` - `acknowledgements: Array<string>` The constructor only assigns `courseCode`, `title`, `credits`, `prerequisites`, `enrolledStudents` (the 5 real fields, each used by a method). The 8 above are declared with a type but no initializer, no constructor assignment, and no reader — under the workspace's `strict:false` they don't even trip `strictPropertyInitialization`, so they've sat silently as `undefined`. ## Why not just mark them readonly That's what a naive S2933 fix would do, but marking dead fields `readonly` papers over the real problem. This looks like an aspirational data model someone stubbed out and never wired up. ## Fix options (needs a human decision) 1. **Delete** the 8 fields if `Course` is meant to be the lightweight enroll/prereq class it currently behaves as — *(recommended; simplest, and `Course`'s only live behavior is enrollment + prerequisites)*, **or** 2. **Wire them up** — add them to the constructor / a builder and the consumers that should populate course metadata, if the richer model was the intent. Low priority / tech-debt. Filed so the S2933 sweep can skip this file cleanly rather than adding misleading `readonly` to dead members.
Author
Owner

Re-verified against origin/masterstill present, and the count is right. projects/spikersoft/src/app/_components/classes/course.ts is 43 lines; the constructor assigns only courseCode, title, credits, prerequisites, enrolledStudents.

The 8 fields that are neither assigned nor read, at course.ts:2-9: description, audience, duration, format, assessment, certification, objectives, acknowledgements.

Two additions worth folding into the cleanup while someone is in there:

  • courseCode (:11) and credits (:13) are write-only — assigned in the constructor, never read. Only title has a reader (getTitle()). So the effective dead surface is 10 of 13 fields, not 8.
  • That these compile at all means noUnusedLocals-style checking isn't catching unused private class members here. Worth a glance at the tsconfig if you want this class of dead code caught automatically rather than by review.

Notes were accurate; no work has landed.

Re-verified against `origin/master` — **still present, and the count is right.** `projects/spikersoft/src/app/_components/classes/course.ts` is 43 lines; the constructor assigns only `courseCode`, `title`, `credits`, `prerequisites`, `enrolledStudents`. The 8 fields that are neither assigned nor read, at `course.ts:2-9`: `description`, `audience`, `duration`, `format`, `assessment`, `certification`, `objectives`, `acknowledgements`. Two additions worth folding into the cleanup while someone is in there: - `courseCode` (`:11`) and `credits` (`:13`) are **write-only** — assigned in the constructor, never read. Only `title` has a reader (`getTitle()`). So the effective dead surface is 10 of 13 fields, not 8. - That these compile at all means `noUnusedLocals`-style checking isn't catching unused private class members here. Worth a glance at the tsconfig if you want this class of dead code caught automatically rather than by review. Notes were accurate; no work has landed.
Sign in to join this conversation.