DSDS authoring style guide — DSDS 0.23.0
How to order things inside a DSDS document, so every document reads the same way no matter who wrote it.
How to order things inside a DSDS document, so every document reads the same way no matter who wrote it.
None of this changes whether a document is valid. The schema accepts any order. Most of this guide you never have to apply by hand:
#
The schema is the style guideWrite in the order the schema lists them. The order of fields and options in the schema reflects this guide's recommendation for how to organize a document. When in doubt, copy how the schema does it.
#
The patterns behind these rulesEverything below is one of a few ideas, applied to a different part of a document. Learn these and you can usually work out the specific rule.
Field order comes from the schema. List order comes from this guide. Each schema follows the style guide for field order. Which entry, section, or item comes first in a list is something a schema can't express, so this guide describes it.
Broad to specific. The widest thing leads:
Nothing comes before the thing it's built on. Tokens before the themes that override them, themes before the components that use them. Read top to bottom and you meet every idea before anything that depends on it.
Shared fields before specific ones. The fields every kind has come first, then the fields one kind adds. A
Catch-alls go last.
Where no rule decides, keep the order you wrote. Don't alphabetize. Items sharing a
#
1. Base documents and A base document is the outermost object. Its fields go in the order seen in
#
Entry order, inside When a base document holds several entries, order the entries themselves by
system : Always first since it contextualizes everything contained within.token : Defines the attributes that themes and components are created from.theme : Built from tokens, so only makes sense to come after.component : Built from tokens and themes.entry : Always last since it can cover a broad set of topics. Onboarding and overview content that wants to be read first belongs in thesystem entry's own sections — putting anentry ahead of the tokens and components is whatDSDS-21 reports.
This follows the same idea as §4: Broadest first, and follow the dependency chain. This theoretically means that all prerequisite information is provided up front for an entry.
Within one kind, use whatever order reads best. Avoid arbitrary ordering, such as alphabetical when another order is better for comprehension. For example, a scale reads better as
#
2. EntriesFollow the high-level order:
- Shared entry fields except
$extensions defined inentries/entry.schema.yaml . - Then that kind's own fields, defined in
entries/ . A custom kind has no file of its own, so should follow the high-level guidance..schema.yaml - Then
$extensions . All information that adds to the schema goes last.
#
A trait's own fieldsA component's
#
3. A
#
4. Sections #
A section's own fieldsA section leads with the fields that say what it is:
That's the same reason the identifying field leads everywhere. On an entry or a section that field is
#
Keep each kind togetherIf an entry has more than one section, put all the sections of the same kind side by side — every
#
Kind order: broadest firstOrder section kinds like this:
guidelines — the broadest question. Should I use this at all, and how do I use it properly?definitions — reference material: parts, terms, a glossary. Narrower than guidelines, because it's about this entry's own parts and words. Wider than a set of steps.steps — one procedure or checklist. The narrowest of the three, because it's one exact sequence rather than general advice.section (the plain kind) — prose that didn't fit the other three. Last, because it's the fallback.
That's the order
#
Within Guidelines sorts content by: how broad first, who it's for second.
Guidelines should lead with when to use, then describe how to use it. That's the order
framing: when-to-use : Does it make sense to use?framing: how-to-use : If so, how do you use it? Leavingframing out means this — it's the default that file declares.
A section's
Sections in the same breadth tier are then ordered by how broad the audience is. The order
for: all — also what you get by leavingfor out, since it's the default that file declares. So an omittedfor sorts first, not last.for: human for: agent
#
5. Section items #
An item's own fieldsOrder an item's fields the way its own schema file lists them.
| Shape | Its schema file |
|---|---|
| A | |
| A | |
| A |
#
Guideline item order, by Order items by
Order items at the same level in whatever way aids comprehension. Ideally, group subject matter of the same level together. Don't alphabetize items that share a level — that's an arbitrary order dressed up as a rule.
#
6. Refs and combos #
Combos: by subject, then levelCombos group by: subject first, level second. Keep every combo for one subject together, so a reader checking one trait or token finds all of its rules in one place. Within a subject, order them by
Which subject goes first is up to you — put the one that matters most where a reader will look first. Don't alphabetize, same as everywhere else.
A combo reads as one sentence: this subject, at this strength, with these things. That's the order
subject : What is the rule about? A trait, a token, or an entry.level : Does it permit or forbid and how strictly?items : What does the rule apply to?note : Why does it hold?
#
Refs: what it points at, then what kind of pointerA ref answers what it points at before what kind of pointer it is. That's the order
to orhref : What does this point at?to for something in this document,href for anything outside it. Exactly one of the two.rel : What kind of pointer is it? Left out in a field named for one kind of pointer (uses ,extends ,alternatives ,evidence ,checks ,refines ,replacedBy ,specs ), where the field says it.role : What does the thing being pointed at do here?note : Anything else worth saying about the connection.
#
Inline links: a pointer for a relationship, a link for a mentionWhen prose mentions another part of the system, link to it instead of writing its id in backticks. A validator checks a
for a named thing: an entry, a definition, a step, or a trait or value with aname . The text comes from the target, so it stays right after a rename.[keep the focus ring visible](dsds:shared-a11y#focus-visible) for a guideline, which has no short name, and anywhere the sentence needs its own words.- Give a link's target its own
id , and don't change it. An item without one is addressed by a slug of its text, so rewording the rule breaks every link to it. Rename by changingname , neverid . For something that gets renamed often, or that other tools link to, a lowercase UUID makes a goodid ; still shows itsname . - A link isn't a relationship. If the entry depends on the thing it mentions, say so in
uses too. A tool answering "what does changing this affect?" reads pointers, not prose.
This is about reading order, not field order, so
#
7. A complete example #
ToolingTwo tools cover this guide, split by whether the order is a fact or a choice.
dsds-format applies the orders that have one right answer. Every field order comes from a schema file, and combos are an unordered set of rules. It moves lines and nothing else: text, comments and wrapping stay as they are, a comment moves with the field below it, and the result has to hold exactly the same data as before.dsds-format --check changes nothing and exits 1 if a file needs formatting, for CI. In this repo,npm run format runs it andnpm run check runs the check.dsds-lint reports the orders that are a reading choice — entries, sections, guideline items. An author can have a reason to break them, so they stay advice: three warning-only rules inschema/conformance-rules.yaml , run withnpm run lint .
Until 0.22.0, four more lint rules (
#
What's coveredEvery rule in this guide is covered except one, and that one can't be.
| Rule | Where | Covered by |
|---|---|---|
| A base document's own fields | §1 | |
| A | §1 | |
| Entry order inside | §1 | |
| An entry's own fields | §2 | |
| A trait's own fields | §2 | |
| A trait value's own fields | §2 | |
| A | §3 | |
| A section's own fields | §4 | |
| Same-kind sections kept together | §4 | |
| Section kind order | §4 | |
| Breadth, then audience, among | §4 | |
| An item's own fields | §5 | |
| Guideline items by | §5 | |
| A combo's own fields | §6 | |
| Combos for one subject kept together, then by level | §6 | |
| A ref's own fields | §6 | |
| Order within one entry kind, or one | §1, §5 | can't be — it's a judgment call |
Every sort reads a field, and classification never sorts.
Field order has one source: the schema files. The tables on the Schema page are generated from each schema file's own order,