spec_driven_docs/domain/
rule_id.rs1use std::fmt;
10
11macro_rules! rule_ids {
12 ($($variant:ident => $id:literal,)+) => {
13 #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
15 pub enum RuleId {
16 $(
17 #[doc = $id]
18 $variant,
19 )+
20 }
21
22 impl RuleId {
23 pub const ALL: &'static [Self] = &[$(Self::$variant),+];
25
26 #[must_use]
28 pub const fn as_str(self) -> &'static str {
29 match self {
30 $(Self::$variant => $id),+
31 }
32 }
33 }
34 };
35}
36
37rule_ids! {
38 CellCarriesOneReference => "comparison-docs:a-cell-carries-one-reference",
39 ComparisonCarriesALegend => "comparison-docs:a-comparison-carries-a-legend",
40 VerdictCarriesItsWord => "comparison-docs:a-verdict-carries-its-word",
41 EveryTableIsDated => "comparison-docs:every-table-is-dated",
42 TablePipesAreEscaped => "comparison-docs:table-pipes-are-escaped",
43 BodyStaysWithinWordCap => "decision-records:body-stays-within-350-words",
44 FilenameCarriesNoDigit => "decision-records:filename-carries-no-digit",
45 MergedRecordIsPermanent => "decision-records:merged-record-is-permanent",
46 RecordIsNotRevised => "decision-records:record-is-not-revised",
47 InitializationPreservesProjectContent => "distribution:initialization-preserves-project-content",
48 InstancesOperateOffline => "distribution:instances-operate-offline",
49 ManifestIdentifiesEveryOwnedFile => "distribution:manifest-identifies-every-owned-file",
50 UpgradeConflictsAreAtomic => "distribution:upgrade-conflicts-are-atomic",
51 AuthorInstructionsStayWithinBudget => "docs-format:author-instructions-stay-within-budget",
52 ChapterStaysWithinLineCap => "docs-format:chapter-stays-within-200-lines",
53 DocumentStatesThePresent => "docs-format:document-states-the-present",
54 DocumentUsesStructuralMarkdownOnly => "docs-format:document-uses-structural-markdown-only",
55 EveryBudgetCarriesAGate => "docs-format:every-budget-carries-a-gate",
56 FenceDeclaresALanguage => "docs-format:fence-declares-a-language",
57 ProseStaysUnwrapped => "docs-format:prose-stays-unwrapped",
58 KindPrefixCarriesASlug => "docs-foundations:a-kind-prefix-carries-a-slug",
59 ArtifactFilenamesCarryAKindPrefix => "docs-foundations:artifact-filenames-carry-a-kind-prefix",
60 CompanionArtifactsShareTheSpecName => "docs-foundations:companion-artifacts-share-the-spec-name",
61 SpecStatesThePresent => "docs-foundations:spec-states-the-present",
62 SpecWinsOverRecord => "docs-foundations:spec-wins-over-record",
63 SpecsAreCentralized => "docs-foundations:specs-are-centralized",
64 ProhibitionsAreCapped => "docs-specs:prohibitions-are-capped",
65 RequirementCarriesAVerification => "docs-specs:requirement-carries-a-verification",
66 RequirementCarriesFiveParts => "docs-specs:requirement-carries-five-parts",
67 RuleIdIsUniqueAndSlugged => "docs-specs:rule-id-is-unique-and-slugged",
68 RuleIdOutlivesItsSentence => "docs-specs:rule-id-outlives-its-sentence",
69 SpecStaysWithinLineCap => "docs-specs:spec-stays-within-300-lines",
70 StatementUsesAnEarsPattern => "docs-specs:statement-uses-an-ears-pattern",
71 UnenforcedRulesAreDeclared => "docs-specs:unenforced-rules-are-declared",
72 VerificationNamesALiveHook => "docs-specs:verification-names-a-live-hook",
73 BugzillaReportBodyFitsReportWidth => "known-issues:a-bugzilla-report-body-fits-in-79-columns",
74 FiledRecordCarriesItsReport => "known-issues:a-filed-record-carries-its-report",
75 RecordCarriesItsRetirementCondition => "known-issues:a-record-carries-its-retirement-condition",
76 RecordWalksTheMechanism => "known-issues:a-record-walks-the-mechanism",
77 CaseIdIsASlug => "known-issues:case-id-is-a-slug",
78 CanonGateIsNotDelivered => "release:a-canon-gate-is-not-delivered",
79 ReleasedVersionIsNotReAuthored => "release:a-released-version-is-not-re-authored",
80 TagDerivesFromTheVersionFile => "release:a-tag-derives-from-the-version-file",
81 LicenseDeclaresBothHalves => "release:license-declares-both-halves",
82 DeliveredGateSetIsDeclaredOnce => "release:the-delivered-gate-set-is-declared-once",
83 VersionsAreSemanticAndAligned => "release:versions-are-semantic-and-aligned",
84 CommentCitesTheRule => "spec-to-code:a-comment-cites-the-rule",
85 CommentNamesNoRecord => "spec-to-code:a-comment-names-no-record",
86 GateMessageCitesTheRule => "spec-to-code:a-gate-message-cites-the-rule",
87 SpecChangeIsTyped => "spec-to-code:a-spec-change-is-typed",
88 SpecMayLeadItsCode => "spec-to-code:a-spec-may-lead-its-code",
89 SuppressionNamesItsCase => "spec-to-code:a-suppression-names-its-case",
90 EntryDocumentCitesRuleIds => "spec-to-code:an-entry-document-cites-rule-ids",
91 UnenactedRulesAreTheBacklog => "spec-to-code:unenacted-rules-are-the-backlog",
92}
93
94impl fmt::Display for RuleId {
95 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
96 f.write_str(self.as_str())
97 }
98}
99
100#[cfg(test)]
101mod tests {
102 use super::*;
103
104 #[test]
105 fn slugs_are_well_formed_and_unique() {
106 let mut seen = std::collections::BTreeSet::new();
107 for rule in RuleId::ALL {
108 let id = rule.as_str();
109 let (domain, name) = id.split_once(':').unwrap();
110 let assert_slug = |part: &str| {
111 assert!(!part.is_empty(), "{id} has an empty half");
112 assert!(
113 part.bytes()
114 .all(|b| b.is_ascii_lowercase() || b.is_ascii_digit() || b == b'-'),
115 "{id} is not a slug pair"
116 );
117 };
118 assert_slug(domain);
119 assert_slug(name);
120 assert!(seen.insert(id), "{id} is duplicated");
121 }
122 }
123
124 #[test]
125 fn display_renders_the_slug_pair() {
126 assert_eq!(
127 RuleId::ChapterStaysWithinLineCap.to_string(),
128 "docs-format:chapter-stays-within-200-lines"
129 );
130 }
131}