# `Statifier.Validator.Checks.History`
[🔗](https://github.com/riddler/statifier-ex/blob/v2.0.0/lib/statifier/validator/checks/history.ex#L1)

Check 5 (spec 3.10): a `:history` state's placement, default transition,
and `type`. Four independent facts, per `:history` state in the document:

- `{:history_bad_parent, id, parent_kind}` when the parent is not a
  compound `<state>` or a `<parallel>` (`Context.compound?/1`, Decision
  6) - the document root, a `:final`, and another `:history` are all
  illegal parents.
- `Statifier.Validator.Checks.DefaultTransition`'s shared sub-check with
  `owner: {:history, id}` - required, exactly one, a non-null target, no
  `event`, no `cond` (spec 3.10 requires the default transition
  unconditionally, stricter than a looser "when present" reading).
- `{:initial_not_descendant, target, parent_id}` when a resolved default
  target is not a descendant of the history's own **parent** (spec 3.10)
  - not of the history state itself, which has no descendants of its
    own to test against. Reuses check 3's constructor: this is the same
    shape of mistake, just against a different parent. Skipped when the
    target does not resolve at all (`Statifier.Validator.Checks.Targets`
    already reported that) or when the parent is not compound - a
    non-compound parent has already been reported by
    `:history_bad_parent`, and testing descendancy against it (an id that
    may not even exist, for the document root) would be a second,
    meaningless error for the same mistake.
- `{:history_bad_type, raw}` when `type` was written and, sliced back out
  of `context.source`, is neither `"shallow"` nor `"deep"`.
  Lowering silently maps any out-of-range value to the `:shallow`
  default (Residual Note 2), so the atom on `%State{}` alone cannot tell
  `type="shallow"` from `type="sideways"` - only the raw source text can.

# `check`

```elixir
@spec check(
  document :: Statifier.Document.t(),
  context :: Statifier.Validator.Context.t()
) :: [
  Statifier.Validator.Error.t()
]
```

Returns, per `:history` state in the document, any combination of a
`:history_bad_parent` error (the parent is not a compound `<state>` or
`<parallel>`), the shared default-transition errors from
`Statifier.Validator.Checks.DefaultTransition`, an `:initial_not_descendant`
error (the default transition's target is not a descendant of the
history's own parent), and a `:history_bad_type` error (a written `type`
that is neither `"shallow"` nor `"deep"`). Returns `[]` when every
`:history` state's placement, default transition, and type are all legal.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
