code-quality/law-of-demeter

law of demeter Shipped

What this lens looks for

Flag train-wreck chains that traverse returned objects to reach a target (a.getB().getC().doThing()), feature envy (a method pulling several fields off another object to compute what belongs there), and ask-then-act (querying state then branching/mutating) — prefer a delegating method or telling the object to act. SHOULD-level: treat a chain as a refactor signal, not an automatic defect, and confirm it crosses object boundaries first.

What its verifier checks

Train wrecks crossing object boundaries flagged as refactor signals (delegating method or relocated behavior); feature-envy computations moved onto the owning object; ask-then-act replaced with tell-don't-ask where it enforces a rule. Do NOT flag fluent builders/DSLs (self-returning), immutable map/filter/reduce pipelines, boundary DTOs/config/response models, or stdlib value types (dates/paths/URIs); never demand a wrapper whose only job is to relay one call to a stable data object.