lint rule: primitive-obsession on raw-hash ivar (reek DataClump approximation) #207

Closed
opened 2026-08-01 14:16:57 +00:00 by jared · 2 comments
Owner

Migrated from jared/os-sdlc#33 (repo retired).

Problem

A primitive-typed ivar (e.g. a raw Hash) is touched by 3+ methods in a class, each re-encoding its own piece of a shared concept (e.g. validation, default-fill lookup, aggregation). Primitive obsession: no owning object for the concept.

Detection

  • Inputs: lib/ Ruby source.
  • Algorithm: reek-style DataClump/FeatureEnvy approximation -- flag a primitive-typed ivar (Hash/Array) referenced from 3+ methods within a class, each performing distinct operations on it.
  • Failure message: "ivar (Hash/Array) is referenced by 3+ methods, each re-encoding its own rules. Extract a value object owning the shared behavior."

Correction

Extract a value object wrapping the primitive, owning its access/validation/default behavior; the original class delegates to it.

Pass/fail examples

  • Must fail: a raw Hash/Array ivar touched by 3+ methods, each doing distinct validation/lookup/aggregation work on it.
  • Must pass: the ivar's behavior extracted into a dedicated value object; the class delegates to it.

Provenance

Fable finding. Run 18 (ticket #18, decision-dice sandbox, now retired), dual review, 2026-07-21.

Implementation plan

NEEDS SCOPING before implementation: "3+ methods, each performing distinct operations" is a judgment call (what counts as "distinct"?) rather than a clean AST pattern -- this is closer to a reek smell than a rubocop-style structural cop. Needs a tighter, mechanically-checkable definition (e.g. threshold on method count referencing the ivar, regardless of operation distinctness) before it can be implemented as a deterministic cop.

Migrated from jared/os-sdlc#33 (repo retired). ## Problem A primitive-typed ivar (e.g. a raw Hash) is touched by 3+ methods in a class, each re-encoding its own piece of a shared concept (e.g. validation, default-fill lookup, aggregation). Primitive obsession: no owning object for the concept. ## Detection - **Inputs:** lib/ Ruby source. - **Algorithm:** reek-style DataClump/FeatureEnvy approximation -- flag a primitive-typed ivar (Hash/Array) referenced from 3+ methods within a class, each performing distinct operations on it. - **Failure message:** "ivar (Hash/Array) is referenced by 3+ methods, each re-encoding its own rules. Extract a value object owning the shared behavior." ## Correction Extract a value object wrapping the primitive, owning its access/validation/default behavior; the original class delegates to it. ## Pass/fail examples - **Must fail:** a raw Hash/Array ivar touched by 3+ methods, each doing distinct validation/lookup/aggregation work on it. - **Must pass:** the ivar's behavior extracted into a dedicated value object; the class delegates to it. ## Provenance Fable finding. Run 18 (ticket #18, decision-dice sandbox, now retired), dual review, 2026-07-21. ## Implementation plan NEEDS SCOPING before implementation: "3+ methods, each performing distinct operations" is a judgment call (what counts as "distinct"?) rather than a clean AST pattern -- this is closer to a reek smell than a rubocop-style structural cop. Needs a tighter, mechanically-checkable definition (e.g. threshold on method count referencing the ivar, regardless of operation distinctness) before it can be implemented as a deterministic cop.
Author
Owner

This was generated by AI during triage.

Recommendation for maintainer: drop the "distinct operations" judgment call and use a pure reference-count threshold — flag any Hash/Array ivar referenced (read or write) from 3+ instance methods in a class, regardless of what each method does with it. This is mechanically AST-checkable (ivar node count grouped by enclosing def) and errs toward false positives over false negatives, acceptable for an advisory cop. This fully specifies the detection rule; no open maintainer decision remains.

> *This was generated by AI during triage.* Recommendation for maintainer: drop the "distinct operations" judgment call and use a pure reference-count threshold — flag any Hash/Array ivar referenced (read or write) from 3+ instance methods in a class, regardless of what each method does with it. This is mechanically AST-checkable (ivar node count grouped by enclosing def) and errs toward false positives over false negatives, acceptable for an advisory cop. This fully specifies the detection rule; no open maintainer decision remains.
Author
Owner

This was generated by AI during triage.

Implemented via os-sdlc pipeline (APPROVE). Mechanical scoping per triage: Sdlc/Structural/PrimitiveObsessedIvar (Hash/Array literal in initialize + 3+ referencing methods). Merged to main in e2960c3.

> *This was generated by AI during triage.* Implemented via os-sdlc pipeline (APPROVE). Mechanical scoping per triage: Sdlc/Structural/PrimitiveObsessedIvar (Hash/Array literal in initialize + 3+ referencing methods). Merged to main in e2960c3.
jared 2026-08-01 20:30:07 +00:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
jared/cc-os#207
No description provided.