Skip to main content

SKY-U007 · Dead code

Unused TypeScript enum member

Low

A member has no literal read in a module-local enum, or in an exported enum of an internal module whose direct named imports are fully known. Public and opaque enum surfaces remain live.

Languages
TypeScript
Turned on by
skylos .
Quality gate
counted toward the gate limits (full and diff scans). Reported in unused_variables with its own SKY-U007 ID; counts toward max_dead_code, which is unlimited by default.
Finding type
review
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

Why it matters

An obsolete enum member can keep a removed state or workflow looking supported. Removing numeric members can change later implicit values, so the finding requires review.

What Skylos flags

src/index.ts · TypeScriptReported on line 4
export {};enum Status {  Ready = "ready",  Spare = "spare",}console.log(Status.Ready);

What Skylos leaves alone

src/index.ts · TypeScript
export {};enum Status {  Ready = "ready",  Spare = "spare",}console.log(Object.values(Status));

Why Skylos leaves it alone

Reflection consumes the enum object without proving which members a downstream consumer needs, so all members remain live.

More languages

TypeScript

Flagged

package.json · JSON
{"name":"app","private":true,"type":"module","main":"app.ts"}
status.ts · TypeScriptReported on line 3
export enum Status {  Ready = "ready",  Spare = "spare"}
app.ts · TypeScript
import { Status as Mode } from "./status";console.log(Mode.Ready);

Not flagged

package.json: same as in the flagged example.

status.ts: same as in the flagged example.

app.ts · TypeScript
import { Status as Mode } from "./status";console.log(Object.values(Mode));

Why Skylos leaves it alone

The source inventory is known, but reflection makes the member demand opaque. The enum is retained rather than narrowed.

How Skylos decides

  1. Reads implementation enums in explicit TypeScript modules. Local enums can be narrowed inside their module; an exported enum requires an internal module (not a package.json entry, tool or framework entry, file named by path or module no file imports, the SKY-E004 notion) and a complete source inventory. The package need not be private.
  2. For an exported enum, resolves direct named imports and aliases to their provider before combining literal member reads across files. Namespace imports, re-exports and dynamic loaders prevent this proof. A Vue, Svelte or Astro component, HTML module script or MDX document that imports the enum's module is read as an opaque consumer of that module's enums (a template can read members its script never names); other modules keep exact narrowing. An unresolved import holds back only the module its last segment names, or the workspace package a bare specifier names; a relative import that matches no file cannot load an existing enum.
  3. @public, @alpha and @beta JSDoc tags on an enum or member keep it live.
  4. Resolves literal member reads and constant aliases. Dynamic indexing, reflection, mutation, escapes, declaration merging and effectful initializers decline member narrowing.
  5. Retains members referenced by other initializers. If no member is read, leaves the entire enum to the existing unused-owner finding instead of listing every member.
  6. Reports LOW at the member declaration. analysis_summary.enum_member_analysis identifies scope local_and_internal_module_enums and records checked enums, abstentions, unresolved imports and incomplete source graph reads.

How to fix it

Remove a genuinely obsolete member after checking that remaining enum values and external contracts stay correct. This string-valued example preserves the retained member value.

src/index.ts · TypeScript · the fix, against the flagged file
export {};enum Status {  Ready = "ready",Removed:   Spare = "spare",}console.log(Status.Ready);

When it can be wrong

  • Code loaded outside the selected project may impose a contract the module does not expose statically.
  • An unread numeric member can still influence later automatically assigned values; the rule does not authorize automatic removal.

Seeing a case that isn't listed here? Report the wrong result so the rule can be fixed. Don't paste company code: describe the shape of it.

How to silence it

  • Set [tool.skylos] ignore = ["SKY-U007"] to disable this rule project-wide.

From the Skylos rule handbook, Skylos 5.8.0 (commit 5b880b0). All rules.