swissshepherd

schema_docs rule

The primary rule. Validates argument and attribute documentation against the provider schema.

Sub-checks

All enabled by default; disable individually via the rule’s config block.

Sub-check What it validates
byline First paragraph after section heading matches expected byline text (from type)
coverage Every schema field is documented, in its one home section and only there (a field listed in both reference sections is an error, also reported with only labels on); every schema field is documented in the section its path resolves to; every documented field exists at every path its section documents; a section shared by several paths is right for all of them; headings that document nothing, or the same key twice, are reported (see Coverage: which section documents a block)
deprecated Deprecation status matches between schema and docs (both directions); a mismatch is an error. Fields of a cty object type (list(object({...})) and the like) aren’t checked: the schema JSON has no deprecation flag for them (object-typed-attributes.md)
description Descriptions don’t start with weak/redundant/meta prefixes (“The “, “This “, “Contains “, “Used “, etc.). One finding per bullet, so same-named bullets in different sections are each reported
format No code blocks in arg/attr sections; single-line attrs; uninterrupted lists
heading Block headings match the preferred template style. Style only: whether a heading documents the right block is coverage’s job
labels Arguments carry a present, schema-correct label — (Required)/(Optional), or (Read-Only) for read-only attributes when allow_inline_read_only = true; attributes carry none. A wrong label is an error, a missing one a warning
ordering Attributes alphabetical (single-byline lists as one group; split required/optional bylines as separate groups)

Config

check "schema_docs" {
  # Sub-check toggles
  byline      = true
  coverage    = true
  deprecated  = true
  description = true
  format      = true
  heading     = true
  labels      = true
  ordering    = true

  # Heading templates (see "Heading templates" docs)
  block_heading_styles        = ["`{Block}` Block", "{Block}", "{Title}"]
  prefer_block_heading_styles = ["`{Block}` Block"]

  # Coverage options
  ignore_deprecated      = true                     # skip deprecated schema attrs
  implicit_attributes    = ["id", "tags_all"]       # never flagged as undocumented
  allow_phantoms         = ["tags", "tags_all"]     # never flagged as phantom
  skip_blocks            = ["timeouts"]             # blocks skipped entirely, by exact schema path
  skip_blocks_file       = "website/skip-blocks.txt" # same, one path per line; merged with skip_blocks.
                                                    # Setting either replaces the default ["timeouts"].
  allow_inline_read_only = false                    # see "Schema model" below
  allow_either_section   = ["data_source/tags"]     # Optional+Computed fields that may be outputs: either
                                                    # section, not both (see "Schema model"). Default: none.

  # Description options
  # Overrides the default weak/redundant/meta starts. Default:
  #   "A ", "An ", "The ", "This ", "It ",
  #   "Indicates ", "Specifies ", "Describes ", "Defines ",
  #   "Contains ", "Determines ", "Identifies ", "Represents ", "Denotes ", "Holds ", "Used "
  bad_prefixes = ["A ", "An ", "The ", "This ", "Specifies "]

  # Format options
  no_code_blocks              = true   # no fenced code blocks in arg/attr sections
  single_line_attrs           = true   # each attribute on one line
  uninterrupted_lists         = true   # no paragraphs between list items
  allow_attribute_indentation = true   # allow indented sub-attributes in Attribute Reference (default: true)

  # Object-typed attribute coverage (opt-in; default false)
  nested_object_attributes    = true   # check fields of list(object)/set(object)/object attributes

  # Per-target sub-check toggles (see "Per-target overrides")
  override {
    targets  = ["resource/aws_quicksight_analysis"]
    coverage = false
  }
}

Doc styles

doc_style = "tfplugindocs" reads the one ## Schema section tfplugindocs writes, taking each field’s label from the Required/Optional/Read-Only group it’s listed under, and changes some defaults: allow_inline_read_only is always on, skip_blocks is empty, nested_object_attributes is on, and description and format are off. See doc-style.md.

A doc missing every section a field may be documented in gets one warning per missing section naming the unchecked fields, in place of per-field “not documented” findings (doc-style.md §3).

Severity

schema_docs reports most findings as errors and some as warnings: advisories, such as a heading that resolves to no block, and findings that roll out gradually, such as a misplaced root scalar. severity = "warning" or "error" on the check block replaces the severity of all of them, so "error" turns the advisories into errors too. It applies to every target; an override block can’t set it.

Per-target overrides

ignore_targets turns off every sub-check for a target. An override block turns off, or on, only the sub-checks it names, for only the targets it lists:

check "schema_docs" {
  enabled = true
  coverage = true
  labels   = true

  override {
    targets      = ["resource/aws_quicksight_analysis", "resource/aws_quicksight_dashboard"]
    targets_file = "website/schema-docs-no-coverage.txt"
    coverage     = false
  }
}

A sub-check switched off by an override is off for that target in every respect, as if it were off for the whole check. Sub-checks that defer to it report the finding themselves. For example, labels reports a computed-only field labeled (Optional) in strict mode, which it otherwise leaves to coverage.

Object-typed attributes (nested_object_attributes)

Legacy list(object({...})) / set(object({...})) / bare object({...}) attributes carry their fields as a nested type, not as a schema block. By default swissshepherd treats such an attribute as a single leaf: its inner fields are neither required to be documented nor style-checked. A section whose heading names one (### `items`) isn’t reported as a phantom block, but its bullets aren’t checked against the object’s fields either, so a misspelled or nonexistent field there passes silently. Enable the option to check them.

Set nested_object_attributes = true to model those fields as nested blocks. When enabled:

The cty type encoding of an object (list/set/map(object({...})), object) records field names and types but no per-field Required/Optional/Computed. swissshepherd therefore uses the parent attribute’s configurability:

This is off by default because enabling it surfaces a large number of new findings in docs that previously passed. Roll it out gradually — stage with ignore_targets / skip_blocks, or enable it once the affected docs are clean.

For the full rationale behind the parent-configurability model and the ConfigUnknown flag — why some object fields cannot be classified into a specific section, the proto5 constraint that causes it, and the future-alignment path — see Object-typed attributes, proto5, and the ConfigUnknown escape hatch.

Nested fields documented under a shared or prose-introduced subsection

Coverage decides which section documents a block from section headings alone, never from links or position, because a reader looking at a section can’t see what links to it (see Coverage: one section per path). Two conventions attach a nested block’s fields to it without a dedicated per-path heading:

Schema model: Required / Optional / Read-Only

The coverage sub-check enforces presence of every schema attribute at every depth of nesting. swissshepherd uses the same three-category mental model as tfplugindocs:

Every field has exactly one home, and is listed only there (Field homes, #111). A field listed in both reference sections for the same block is an error whatever its category, with the entry to remove: argument "description" is listed in both Argument Reference (line 4) and Attribute Reference (line 9); remove the Attribute Reference entry. For a computed-only field the Argument Reference entry is the one to remove; for a field with no single home (a ConfigUnknown object field, a computed-only field under allow_inline_read_only = true, a field listed in allow_either_section, or id and other implicit_attributes) the message says to keep one entry. The finding runs when coverage or labels is enabled.

An Optional+Computed field may be an output the schema left Optional (terraform-provider-aws data-source tags, hashicorp/terraform-provider-aws#50491), so findings about one name both fixes. Documented only under Attribute Reference, it gets a warning: move it to Argument Reference if it can be set, or mark it Computed only in the schema if setting it has no effect. Listed in both sections, it’s still an error, with the same two choices. See Field homes.

When the provider knows which such fields are outputs but can’t fix the schema yet, allow_either_section lists them, and each may then be documented in either section, but not both:

check "schema_docs" {
  # Data-source tags are filters on some data sources and outputs on the
  # rest; the schema marks all of them Optional+Computed.
  allow_either_section = ["data_source/tags"]
}

An entry is a schema path (tags, block.tags), bare to apply to every type or qualified by a type name (data_source/tags). It applies only where the field is Optional+Computed (for a child block, where its configurable subtree is all Optional+Computed), so a bare tags never relaxes a resource’s plain Optional tags. A listed field still has to be documented: listed nowhere is “is not documented”, listed in both is an error that says to keep one entry, and an (Optional) label under Attribute Reference is still flagged for removal. Under Argument Reference it carries (Optional), as the schema says. Delete an entry once the schema marks those fields Computed only.

When a configurable argument (Required or Optional, including Optional+Computed) is instead documented under ## Attribute Reference, the labels sub-check reports a misplacement — directing the author to move it to Argument Reference rather than to strip its (correct) label (issues #60, #62). For the design and rationale behind that detection — attribute-granular classification, heading→schema-path resolution, path-based severity (a genuine root scalar is a warning; every nested move is an error), and the measured corpus evidence — see Argument/Attribute-Reference Misplacement. When such an argument carries no label at all, labels can’t tell it from a computed output, so coverage reports it instead, with the label to add: argument "name" is documented under Attribute Reference but is a configurable argument in the schema; move it to Argument Reference and label it (Required). Severity matches the labeled case: a warning at the root, an error when nested (a warning if the field is deprecated).

Label correctness

The labels sub-check validates that a documented argument’s label is both present and correct — a single question, “is the label right?”, not two separate ones. A present label whose value contradicts the schema is as much a defect as a missing one: (Required) on an attribute that is actually Optional misleads users about what they must set.

The invariant is single-valued: exactly one label is correct for each attribute — (Required) when the schema attribute is Required, (Optional) when it is configurable but not required (pure Optional or Optional+Computed), and (Read-Only) when it is computed-only. The other two category labels are wrong; for example an Optional+Computed field must read (Optional), so both (Required) and (Read-Only) on it are reported.

Correctness lives inside the labels sub-check rather than behind a separate toggle: it’s one question, and a second toggle would only split it. Validating the label’s value was always the intent of labels; the earlier presence-only behavior was a gap in that check, not a deliberately narrower feature.

A section is checked against every block it documents, decided the way coverage decides it (see “Coverage: which section documents a block” below). A shared section, such as one `encryption_configuration` heading documenting two blocks, or a partly qualified one, such as `a.z` for block w.a.z, is checked like an exact one, and its finding names the section as written.

The check never fires on a guess. It reports nothing when:

Label additions such as (Required, Forces new resource) do not affect detection: the required/optional state is read from the leading token, and trailing traits are left as authored.

Correctness also covers the inline (Read-Only) label permitted when allow_inline_read_only = true: it is valid only for a genuinely read-only (computed-only) attribute. A configurable (Required/Optional) field mislabeled (Read-Only) is reported the same way, directing the author to the correct (Required)/(Optional) label. Conversely, a computed-only field mislabeled (Required)/(Optional) is reported with use (Read-Only) — but only under allow_inline_read_only = true; in strict mode a computed-only field does not belong in Argument Reference at all, which coverage reports instead, so labels defers to avoid a double finding. The same holds for a (Read-Only) label in strict mode, which isn’t an Argument Reference label. When Attribute Reference already documents the field, the field is listed twice, and the repeated-field finding reports it (remove the Argument Reference entry) instead of labels.

Under ## Attribute Reference the rule is the mirror image: attributes carry no label at all. A (Read-Only) label there is flagged for removal, just as a stray (Required)/(Optional) label is — a configurable field is additionally directed to move to Argument Reference (see Argument/Attribute-Reference Misplacement), unless Argument Reference already lists it, which is a repeat (remove the Attribute Reference entry). This holds regardless of allow_inline_read_only, which only governs inline (Read-Only) in Argument Reference.

Interaction with ordering. In docs that split arguments under The following arguments are required: / optional: bylines, correcting a label changes the group the argument belongs to, so the byline semantics require relocating it under the matching byline and re-alphabetizing. Note that ordering does not enforce that physical placement: it rebuilds the required/optional groups from each bullet’s parsed label — not from the byline it sits under — and checks each derived group alphabetically. It therefore may surface an alphabetical violation when a corrected bullet is left under the wrong byline, but only if the bullet’s name breaks alphabetical order within its label group; a corrected bullet whose name still sorts correctly stays under the wrong byline with no finding. Treat the relocation as a manual step that pairs with the label fix, not something ordering will always catch.

For nested blocks, Read-Only attributes can be documented in any of the following equivalent forms:

The default (allow_inline_read_only = false) preserves the AWS provider’s traditional separation: ## Argument Reference for configurable attributes, ## Attribute Reference for Read-Only ones. Setting the toggle to true permits the tfplugindocs-aligned permissive convention without requiring all docs to convert at once.

Coverage: which section documents a block

A section’s identity comes from its heading alone. Links and position never decide which block a section documents: a reader looking at a section can’t see what links to it. The design, its acceptance cases, and the measured corpus impact are in Coverage: one section per path (#77).

Resolution

For each schema path, coverage looks for one section in Argument Reference and one in Attribute Reference. For w.x.y.z it tries these heading keys in order, taking the first one that names a section:

  1. the full path, w.x.y.z;
  2. two adjacent ancestors and the leaf, nearest first: x.y.z, then w.x.z;
  3. one ancestor and the leaf, nearest first: y.z, x.z, then w.z;
  4. the bare leaf, z.

A dotted key that is itself a different schema path is skipped, so x.z never documents w.x.y.z when the schema also has a block at x.z. Paths in skip_blocks are skipped entirely.

Every field a section lists must exist at every path that resolves to it. A field the schema expects at a path counts as documented if it’s listed in either of that path’s sections, so the misplacement findings, not “is not documented”, handle a field in the wrong reference section.

Shared sections

A section with a short heading (### `z` Block) can serve several paths. That’s fine when the paths are interchangeable, and wrong when they aren’t. A shared section is valid only if, across every path it serves:

Otherwise coverage reports the section once per conflicting field, naming two of the paths and suggesting a qualified heading:

section "z" (line 24) in Argument Reference documents 2 paths; "a2" must be listed for "x.y.z" but doesn't exist at "t.u.z". Qualifying means up to 2 sections: give "x.y.z" a heading that resolves only to paths where "a2" exists, e.g. "`x.y.z` Block"

Existence and child-content conflicts are warnings, because the per-path field findings already report the errors. Label and deprecation conflicts are errors: no single marker is right for every path. This replaces the heading sub-check’s former “is ambiguous” warning, so it now needs coverage enabled.

The per-path field findings point at the cause too. A phantom field in a shared section names the other paths where the field does exist; a missing field names the other paths the section serves where it doesn’t, so the fix is a qualified heading, not another bullet.

Headings that document nothing

Finding Severity Meaning
heading "…" … isn't a recognized block heading, so its bullets aren't checked against the schema warning An H3+ heading in a reference section matches no block_heading_styles template. Its bullets belong to no section; only description still checks them. Suggests a heading when the text names a schema block.
heading "…" … documents no block (…), so its fields aren't checked against the schema warning The heading parses, but no schema path resolves to its key. Headings with no bullets are skipped.
block "P" is not documented (M paths beneath it are also undocumented; K other undocumented paths share the name "L") error No section resolves to P, which has configurable fields. Only the shallowest undocumented block in a subtree is reported; the counts say how much lies beneath it.

Duplicate headings

When two headings in one reference section normalize to the same key, coverage keeps both occurrences and asks whether some assignment of headings to the paths that key serves makes every block exact: listed fields exist, fields whose only home is this section are listed, and labels and deprecation markers are right.

The per-path field findings and the shared-section finding are not emitted for a duplicated key; the fit rule stands in for them.

Prose-introduced lists

A colon-terminated paragraph that names a schema block in backticks is treated as a heading for that block:

The `cloudwatch_logs` object takes the following arguments:

* `role_arn` - (Required) IAM role ARN.

The list documents cloudwatch_logs and gets every check a section gets. Like a heading, the prose stays in effect until the next heading or lead-in, so a code block interrupting its list doesn’t end it. A warning asks for a real heading: list introduced by prose ("…") in Argument Reference documents "cloudwatch_logs" without a block heading; use a block heading, e.g. "cloudwatch_logs Block".

This is a parsing decision, not a coverage one: it applies whether or not coverage is enabled, so ordering, description, labels, and format judge a prose list’s bullets against the block it names. The same holds for bullets under an unparseable heading, which belong to no section for every sub-check.

With nested_object_attributes = true, the indented sub-bullets under a prose list’s bullets move with them, so * `settings` with indented * `level` under prose naming cloudwatch_logs documents cloudwatch_logs.settings.level. This holds under an unparseable heading too.

Exceptions, where reading prose as a heading would credit the wrong block:

Phantom fields

A listed field that doesn’t exist at a path its section serves is an error: documented argument "x" in block "p" does not exist in schema under Argument Reference, documented attribute … under Attribute Reference.

Coverage: phantom block headings

The coverage sub-check also flags H3+ headings inside ## Argument Reference whose name doesn’t match any schema block. Common patterns this catches:

The check is restricted to ## Argument Reference. Block-style headings under ## Attribute Reference (e.g. ### Endpoint, ### master_user_secret) commonly document the structure of computed attributes that have no Block representation in the schema, and are not flagged.

Ordering: single vs. split lists

The ordering sub-check adapts to how arguments are presented in the doc:

The signal comes directly from the byline text, not the order of attributes. Mixing labels in a single-list block (e.g., a (Required) after several (Optional) items) is allowed as long as the names are alphabetical overall.