Documentation
¶
Index ¶
- Variables
- type CheckContext
- type ExampleSectionRule
- type FileCheckContext
- type FileCheckRule
- type FileMatchRule
- type FileRule
- type FrontmatterRule
- type ImportSectionRule
- type RegionArgumentRule
- type Result
- type Rule
- type Runner
- type SchemaDocsRule
- type SectionPresenceRule
- type Severity
- type SignatureSectionRule
- type TimeoutsSectionRule
- type TitleSectionRule
Constants ¶
This section is empty.
Variables ¶
var DefaultAllowPhantoms = []string{"tags", "tags_all"}
DefaultAllowPhantoms are attribute names that may appear in docs without a corresponding schema entry (provider-injected attributes).
var DefaultBadDescriptionPrefixes = []string{
"A ", "An ", "The ", "Indicates ", "Specifies ", "Describes ", "Defines ",
}
DefaultBadDescriptionPrefixes is the list of weak or redundant description starts.
var DefaultImplicitAttributes = []string{"id", "tags_all"}
DefaultImplicitAttributes are attribute names that are always implicitly present in provider docs and don't need explicit documentation entries.
var DefaultSkipBlocks = []string{"timeouts"}
DefaultSkipBlocks are block names that are always skipped.
var DefaultTitleSectionPrefixes = []string{
"Action",
"Data Source",
"Ephemeral",
"Function",
"List Resource",
"Resource",
}
DefaultTitleSectionPrefixes is the allow-list of "<kind>:" prefixes that Terraform Registry and historical legacy layouts accept on a level-1 documentation heading. Kept in sync with tfproviderdocs so migrating providers see identical verdicts. Callers may supply their own list via TitleSectionRule.AllowPrefixes when a provider needs a different set.
Functions ¶
This section is empty.
Types ¶
type CheckContext ¶
type CheckContext struct {
Resource string
DocName string // aliased name used in doc file (empty = same as Resource)
Type *config.Type
Schema *schema.ResourceSchema
FunctionSchema *schema.FunctionSchema
IdentitySchema *schema.IdentitySchema
Doc *doc.Document
}
CheckContext carries all inputs a Rule needs to produce findings.
func (CheckContext) ResourceNames ¶ added in v0.3.0
func (c CheckContext) ResourceNames() []string
ResourceNames returns the resource name and, if different, the doc alias name.
type ExampleSectionRule ¶ added in v0.3.0
type ExampleSectionRule struct {
AllowLanguages []string
}
ExampleSectionRule validates the content of the ## Example Usage section. Checks:
- Heading text is "Example Usage"
- All fenced code blocks use an allowed language (default: terraform, hcl)
- All code blocks contain the resource name
func (*ExampleSectionRule) Check ¶ added in v0.3.0
func (r *ExampleSectionRule) Check(ctx CheckContext) []Result
func (*ExampleSectionRule) Name ¶ added in v0.3.0
func (r *ExampleSectionRule) Name() string
type FileCheckContext ¶
FileCheckContext carries all inputs a FileRule needs to produce findings.
type FileCheckRule ¶ added in v0.4.0
type FileCheckRule struct {
MaxSize int64 // bytes; 0 means use default (500000)
AllowExtensions []string // e.g. [".md", ".html.markdown"]; empty means no check
AllowRegistryExtensions []string // stricter set for registry layout; empty means no check
InlineLinks *bool // when true, flag reference-style links
}
FileCheckRule validates file-level properties: size limit, extension, and link style.
func (*FileCheckRule) CheckFile ¶ added in v0.4.0
func (r *FileCheckRule) CheckFile(ctx FileCheckContext) []Result
func (*FileCheckRule) Name ¶ added in v0.4.0
func (r *FileCheckRule) Name() string
type FileMatchRule ¶ added in v0.4.0
type FileMatchRule struct {
RequireDoc *bool // default true
RequireSchema *bool // default true
MixedLayout *bool // default true
IgnoreMissing []string // resources that don't need a doc file
IgnoreExtra []string // doc files that don't need a schema resource
}
FileMatchRule validates file↔schema alignment:
- require_doc: every schema resource must have a doc file
- require_schema: every doc file must have a matching schema resource
- mixed_layout: can't mix website/docs/ and docs/ layouts
func (*FileMatchRule) Check ¶ added in v0.4.0
func (r *FileMatchRule) Check(cfg *config.Config, ps *schema.ProviderSchema) []Result
Check runs all file_match sub-checks. Called once per invocation by the Runner.
func (*FileMatchRule) Name ¶ added in v0.4.0
func (r *FileMatchRule) Name() string
type FileRule ¶
type FileRule interface {
Name() string
CheckFile(ctx FileCheckContext) []Result
}
FileRule is the interface for checks that operate on the raw bytes of a resource documentation file, independent of the markdown AST. Runner reads each file exactly once per invocation and passes the content to every FileRule alongside the parsed Document that Rules consume.
type FrontmatterRule ¶
type FrontmatterRule struct {
RequireSubcategory bool
RequirePageTitle bool
RequireDescription bool
RequireLayout bool
ForbidSubcategory bool
ForbidPageTitle bool
ForbidDescription bool
ForbidLayout bool
ForbidSidebarCurrent bool
AllowSubcategories []string
// AllowEmptySubcategoryTargets lists target names for which subcategory: ""
// is treated as absent (skips the allowlist check). Use for doc types such
// as functions that legitimately carry no subcategory.
AllowEmptySubcategoryTargets []string
}
FrontmatterRule validates the YAML frontmatter of a provider documentation file — the block delimited by "---" at the top of each .html.markdown / .md file. It is the successor to tfproviderdocs's FrontMatterCheck; the field coverage and error shapes are chosen to find the same problems.
All require/forbid toggles default to false so the rule is inert until configured. AllowSubcategories, when non-empty, restricts the set of valid subcategory values; an empty slice means "any subcategory is fine".
func (*FrontmatterRule) CheckFile ¶
func (r *FrontmatterRule) CheckFile(ctx FileCheckContext) []Result
CheckFile inspects the frontmatter block at the top of content. If no frontmatter block is present, every RequireX toggle produces a result. If the block exists but fails to parse as YAML, a single parse-error result is returned and individual field checks are skipped.
func (*FrontmatterRule) Name ¶
func (r *FrontmatterRule) Name() string
type ImportSectionRule ¶
type ImportSectionRule struct {
RequireIdentitySection bool
}
ImportSectionRule validates the content of the ## Import section. Checks:
- Style: no passive voice ("can be imported"), no "e.g."
- Structure: code blocks present, contain resource name, correct types
- Ordering: terraform blocks before console blocks
- Identity: if resource has identity schema and RequireIdentitySection is true, validates identity import block and ### Identity Schema subsection
func (*ImportSectionRule) Check ¶
func (r *ImportSectionRule) Check(ctx CheckContext) []Result
func (*ImportSectionRule) Name ¶
func (r *ImportSectionRule) Name() string
type RegionArgumentRule ¶ added in v0.4.0
type RegionArgumentRule struct {
// IgnoreResources lists resources that should not be checked for region.
IgnoreResources []string
}
RegionArgumentRule validates that region-aware resources document the "region" argument. This is provider-specific (primarily AWS) and only fires for types with RegionAware = true.
func (*RegionArgumentRule) Check ¶ added in v0.4.0
func (r *RegionArgumentRule) Check(ctx CheckContext) []Result
func (*RegionArgumentRule) Name ¶ added in v0.4.0
func (r *RegionArgumentRule) Name() string
type Result ¶
type Result struct {
Rule string `json:"rule"`
Resource string `json:"resource"`
Path string `json:"path,omitempty"`
Line int `json:"line,omitempty"`
Severity Severity `json:"severity"`
Message string `json:"message"`
Block string `json:"block,omitempty"`
}
Result represents a single finding from a check.
type Rule ¶
type Rule interface {
Name() string
Check(ctx CheckContext) []Result
}
Rule is the interface all per-resource checks implement. A Rule compares a resource's schema against its parsed markdown document. For checks that operate on raw file content (YAML frontmatter, file size, line-level scanning, etc.) implement FileRule instead.
type Runner ¶
type Runner struct {
Schema *schema.ProviderSchema
Config *config.Config
Rules []Rule
FileRules []FileRule
Logger *slog.Logger
HeadingTemplates doc.HeadingTemplates
PreferredHeadingTemplates doc.HeadingTemplates
}
Runner orchestrates checks across every target the provider exposes.
Targets are discovered by iterating the configured types (config.Config.Types) and asking the loaded schema for the names of each type's kind. For each target, Runner resolves the doc file from the type's website_paths templates, reads and parses it once, and invokes every Rule (schema + AST) and every FileRule (raw bytes) against it.
The Runner no longer hard-codes "resource" vs "data source" — everything it does is driven by config.Type definitions. Adding a new Terraform category means adding a type block (and, if block-based, registering a schema accessor); the Runner requires no changes.
func (*Runner) RunAll ¶
RunAll runs every configured rule against every target of every type that swissshepherd can enumerate from the provider schema. Per-file load and parse errors are logged and skipped so a single bad doc does not bring down a full-provider run.
func (*Runner) RunOne ¶
RunOne runs every configured rule against a single named target. If kind is empty, Runner searches every configured type; an ambiguous name (present in multiple types) returns an error naming the candidates so the caller can re-invoke with an explicit --type. When kind is non-empty, only that type is consulted.
RunOne surfaces file-read and parse errors rather than logging-and-skipping because it's the "I asked for this one thing" mode and silence would be misleading.
type SchemaDocsRule ¶ added in v0.3.0
type SchemaDocsRule struct {
// Coverage options
IgnoreDeprecated bool
ImplicitAttributes []string
AllowPhantoms []string
SkipBlocks []string
// AllowInlineReadOnly permits Read-Only (computed-only) attributes to
// be documented inline in Argument Reference with a "(Read-Only)" label,
// alongside Required and Optional siblings, instead of requiring them
// in Attribute Reference. Default false: strict separation — Argument
// Reference is for configurable attributes only.
AllowInlineReadOnly *bool
// Sub-check toggles (nil = enabled)
Coverage *bool
Ordering *bool
Description *bool
Heading *bool
Format *bool
Labels *bool
Byline *bool
Deprecated *bool
// Description options
BadPrefixes []string
// Heading options
Preferred doc.HeadingTemplates
// Format sub-options (nil = enabled)
NoCodeBlocks *bool
SingleLineAttrs *bool
UninterruptedLists *bool
AllowAttributeIndentation *bool // nil/true = allow indented sub-attrs in Attribute Reference
}
SchemaDocsRule validates argument and attribute sections against the schema. Sub-checks (all enabled by default, disable with pointer-to-false):
- Coverage: every schema attr documented, every documented attr in schema
- Ordering: alphabetical within required/optional/unmarked groups
- Description: descriptions don't start with bad prefixes
- Heading: block headings match preferred style
- Format: no code blocks, single-line attrs, uninterrupted lists
- Labels: arguments have (Required)/(Optional), attributes do not
func (*SchemaDocsRule) Check ¶ added in v0.3.0
func (r *SchemaDocsRule) Check(ctx CheckContext) []Result
func (*SchemaDocsRule) Name ¶ added in v0.3.0
func (r *SchemaDocsRule) Name() string
type SectionPresenceRule ¶
SectionPresenceRule enforces the structural integrity of a documentation file: required sections are present, forbidden sections are absent, sections appear in the order declared on the Type, and no stray level-2 headings occur outside the recognized set.
Configuration sources:
- Type.Sections — declares which sections this type may contain, in what order, with required and forbidden flags. The order of section blocks IS the canonical order. A Type with no Sections is treated as "no structural rules" and skipped. Section names may be canonical (title, signature, example, arguments, attributes, timeouts, import) or custom (any lowercase snake_case identifier the type opts into, e.g. "usage_notes", "dependency_management").
- CheckConfig.EnforceOrder — when nil or true, out-of-order sections are reported. Set to false to skip order enforcement.
- CheckConfig.AllowUnknownSections — when nil or false, level-2 headings that do not match a recognized section are reported. Set to true to permit them silently (e.g. for free-form provider docs).
Special handling: Timeouts is also driven by the schema when one is available — the schema's timeouts block, not the Type, decides whether the section is required.
func (*SectionPresenceRule) Check ¶
func (r *SectionPresenceRule) Check(ctx CheckContext) []Result
func (*SectionPresenceRule) Name ¶
func (r *SectionPresenceRule) Name() string
type SignatureSectionRule ¶ added in v0.3.0
type SignatureSectionRule struct{}
SignatureSectionRule validates the content of the ## Signature section. Checks:
- At least one code block is present
- Code block contains the function name
- Code block contains all parameter names from the schema
func (*SignatureSectionRule) Check ¶ added in v0.3.0
func (r *SignatureSectionRule) Check(ctx CheckContext) []Result
func (*SignatureSectionRule) Name ¶ added in v0.3.0
func (r *SignatureSectionRule) Name() string
type TimeoutsSectionRule ¶
type TimeoutsSectionRule struct{}
TimeoutsSectionRule validates that the documented timeout actions match the schema. It checks:
- Every schema timeout action is documented
- Every documented timeout action exists in the schema
No config fields — entirely schema-driven. Path scoping (prefixes, targets) is handled by the Runner's AppliesTo mechanism.
func (*TimeoutsSectionRule) Check ¶
func (r *TimeoutsSectionRule) Check(ctx CheckContext) []Result
func (*TimeoutsSectionRule) Name ¶
func (r *TimeoutsSectionRule) Name() string
type TitleSectionRule ¶
type TitleSectionRule struct {
// AllowPrefixes overrides DefaultTitleSectionPrefixes. Empty uses the
// default.
AllowPrefixes []string
}
TitleSectionRule validates the first-level heading of a provider doc page:
- a title is present,
- its heading level is 1,
- its text begins with one of the allow-listed prefixes followed by ": ",
- no fenced code blocks appear before the first level-2 heading (example code belongs under ## Example Usage).
This is the successor to tfproviderdocs's checkTitleSection. Error messages are chosen to look familiar to anyone migrating from the older tool so the signal a provider acts on is unchanged.
func (*TitleSectionRule) Check ¶
func (r *TitleSectionRule) Check(ctx CheckContext) []Result
func (*TitleSectionRule) Name ¶
func (r *TitleSectionRule) Name() string