Statifier.Validator.Checks.Ids (Statifier v2.0.0)

Copy Markdown View Source

Check 1 (spec 3.14): an ID-typed attribute's value is unique across the document - not only a state's id, but a <data>'s too. 3.14: "all attributes of type "ID" MUST have unique values within an SCXML document", and <data>'s id is type ID (5.3.1) - so a <data id="s1"> colliding with a <state id="s1"> is exactly as much a violation as two states sharing one id, and both join one uniqueness set rather than two separate ones. nil ids are excluded (lib/statifier/document/state.ex - a nil id means "the author omitted an optional attribute", not "no id"; <data> has no nil id, since id is required to build a Data struct at all), and document scope, not session scope, is what this layer can see.

The first occurrence of a repeated id in document order is canonical and reports nothing; every later occurrence gets its own {:duplicate_id, id} error - a <data> colliding with an earlier <state> (or vice versa) is reported at the later element's own span, never at the canonical, earlier one.

A state or <data> written as id="" is a third case, resolved here rather than left open: spec 3.14 types id as an XML Schema ID, whose lexical space excludes the empty string, so an empty id is {:empty_id} - and, like a nil id, it stays out of the uniqueness set entirely. Two elements both written id="" are two empty ids, not a duplicate pair; grouping them would add a third error for a collision that is not one.

Summary

Functions

Returns an :empty_id error for every state or <data> written id="" and a :duplicate_id error for every occurrence of a repeated non-empty id after its first, canonical occurrence in document order. nil ids (an omitted optional attribute) are excluded entirely. Returns [] when every id in the document is unique or absent.

Functions

check(document, context)

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

Returns an :empty_id error for every state or <data> written id="" and a :duplicate_id error for every occurrence of a repeated non-empty id after its first, canonical occurrence in document order. nil ids (an omitted optional attribute) are excluded entirely. Returns [] when every id in the document is unique or absent.