1use 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 CitationResolvesToARule => "decision-records:a-citation-resolves-to-a-rule",
44 BodyStaysWithinWordCap => "decision-records:body-stays-within-350-words",
45 FilenameCarriesNoDigit => "decision-records:filename-carries-no-digit",
46 MergedRecordIsPermanent => "decision-records:merged-record-is-permanent",
47 RecordIsNotRevised => "decision-records:record-is-not-revised",
48 DeclaredLocationIsNamedByItsVariable => "distribution:a-declared-location-is-named-by-its-variable",
49 LandingClassifiesItsTargetFirst => "distribution:a-landing-classifies-its-target-first",
50 SeededRuleRunsNoCanonCommand => "distribution:a-seeded-rule-runs-no-canon-command",
51 SkillChecksItsHostBeforeItPlans => "distribution:a-skill-checks-its-host-before-it-plans",
52 SkillHasOneOwner => "distribution:a-skill-has-one-owner",
53 SkillInstallRestoresOnFailure => "distribution:a-skill-install-restores-on-failure",
54 SkillObeysThePortableFormat => "distribution:a-skill-obeys-the-portable-format",
55 SkillPlansBeforeItActs => "distribution:a-skill-plans-before-it-acts",
56 StaleSkillIsNotAConflict => "distribution:a-stale-skill-is-not-a-conflict",
57 InstallSweepsWhatThePayloadDropped => "distribution:an-install-sweeps-what-the-payload-dropped",
58 InitializationPreservesProjectContent => "distribution:initialization-preserves-project-content",
59 InstancesOperateOffline => "distribution:instances-operate-offline",
60 ManifestIdentifiesEveryOwnedFile => "distribution:manifest-identifies-every-owned-file",
61 DeclarationIsSeededOnceAndThenOwned => "distribution:the-declaration-is-seeded-once-and-then-owned",
62 SharedSkillArtifactsHaveOneHome => "distribution:shared-skill-artifacts-have-one-home",
63 SkillInstallPreviewsBeforeWriting => "distribution:skill-install-previews-before-writing",
64 SkillUninstallRemovesOnlyWhatItWrote => "distribution:skill-uninstall-removes-only-what-it-wrote",
65 SkillsArePartOfThePayload => "distribution:skills-are-part-of-the-payload",
66 TheDoctorAnswersForTheInstalledSkills => "distribution:the-doctor-answers-for-the-installed-skills",
67 ThePayloadNamesNoOtherProject => "distribution:the-payload-names-no-other-project",
68 ThePayloadNamesNoPlanningTool => "distribution:the-payload-names-no-planning-tool",
69 ThePayloadRootsAreDeclaredOnce => "distribution:the-payload-roots-are-declared-once",
70 UpgradeConflictsAreAtomic => "distribution:upgrade-conflicts-are-atomic",
71 UserScopeFilesStayUnrecorded => "distribution:user-scope-files-stay-unrecorded",
72 AuthorInstructionsStayWithinBudget => "docs-format:author-instructions-stay-within-budget",
73 ChapterStaysWithinLineCap => "docs-format:chapter-stays-within-200-lines",
74 DocumentStatesThePresent => "docs-format:document-states-the-present",
75 DocumentUsesStructuralMarkdownOnly => "docs-format:document-uses-structural-markdown-only",
76 EveryBudgetCarriesAGate => "docs-format:every-budget-carries-a-gate",
77 FenceDeclaresALanguage => "docs-format:fence-declares-a-language",
78 ProseStaysUnwrapped => "docs-format:prose-stays-unwrapped",
79 DocumentCarriesNoPersonalPath => "docs-foundations:a-document-carries-no-personal-path",
80 DocumentOwnsWhatItGoverns => "docs-foundations:a-document-owns-what-it-governs",
81 KindPrefixCarriesASlug => "docs-foundations:a-kind-prefix-carries-a-slug",
82 ArtifactFilenamesCarryAKindPrefix => "docs-foundations:artifact-filenames-carry-a-kind-prefix",
83 CompanionArtifactsShareTheSpecName => "docs-foundations:companion-artifacts-share-the-spec-name",
84 SpecStatesThePresent => "docs-foundations:spec-states-the-present",
85 SpecWinsOverRecord => "docs-foundations:spec-wins-over-record",
86 SpecsAreCentralized => "docs-foundations:specs-are-centralized",
87 ProhibitionsAreCapped => "docs-specs:prohibitions-are-capped",
88 RequirementCarriesAVerification => "docs-specs:requirement-carries-a-verification",
89 RequirementCarriesFiveParts => "docs-specs:requirement-carries-five-parts",
90 RuleIdIsUniqueAndSlugged => "docs-specs:rule-id-is-unique-and-slugged",
91 RuleIdOutlivesItsSentence => "docs-specs:rule-id-outlives-its-sentence",
92 SpecStaysWithinLineCap => "docs-specs:spec-stays-within-300-lines",
93 StatementUsesAnEarsPattern => "docs-specs:statement-uses-an-ears-pattern",
94 UnenforcedRulesAreDeclared => "docs-specs:unenforced-rules-are-declared",
95 VerificationNamesALiveHook => "docs-specs:verification-names-a-live-hook",
96 DivergentResultNamesItsDestination => "guides:a-divergent-result-names-its-destination",
97 ManualStepEnumeratesItsInteraction => "guides:a-manual-step-enumerates-its-interaction",
98 StepFollowsItsProducers => "guides:a-step-follows-its-producers",
99 StepIsOneImperativeAction => "guides:a-step-is-one-imperative-action",
100 ExternalFactIsVerifiedUpstream => "guides:an-external-fact-is-verified-upstream",
101 CitationsLiveInTheReferenceZone => "guides:citations-live-in-the-reference-zone",
102 EveryStepCarriesItsCheck => "guides:every-step-carries-its-check",
103 PreconditionsOpenAndVerificationCloses => "guides:preconditions-open-and-verification-closes",
104 TheManifestStaysReadable => "instance:the-manifest-stays-readable",
105 AgentsBlockStaysManaged => "instance:the-agents-block-stays-managed",
106 TrackingRegistryStaysValid => "instance:the-tracking-registry-stays-valid",
107 ProjectDeclaresWhatItsGatesJudge => "instance:the-project-declares-what-its-gates-judge",
108 ManagedBlockAgreesWithTheDeclaration => "instance:the-managed-block-agrees-with-the-declaration",
109 BugzillaReportBodyFitsReportWidth => "known-issues:a-bugzilla-report-body-fits-in-79-columns",
110 FiledRecordCarriesItsReport => "known-issues:a-filed-record-carries-its-report",
111 RecordCarriesItsRetirementCondition => "known-issues:a-record-carries-its-retirement-condition",
112 RecordCarriesOneFilingState => "known-issues:a-record-carries-one-filing-state",
113 RecordCarriesOneState => "known-issues:a-record-carries-one-state",
114 RecordRecordsItsLastCheck => "known-issues:a-record-records-its-last-check",
115 RecordWalksTheMechanism => "known-issues:a-record-walks-the-mechanism",
116 CaseIdIsASlug => "known-issues:case-id-is-a-slug",
117 CanonGateIsNotDelivered => "release:a-canon-gate-is-not-delivered",
118 DeliveredGateReadsWhatTheConventionOwns => "release:a-delivered-gate-reads-what-the-convention-owns",
119 ReleasedVersionIsNotReAuthored => "release:a-released-version-is-not-re-authored",
120 TagDerivesFromTheVersionFile => "release:a-tag-derives-from-the-version-file",
121 LicenseDeclaresBothHalves => "release:license-declares-both-halves",
122 CanonRecordDescribesItsTree => "release:the-canon-record-describes-its-tree",
123 RkPinHasTwoFactsAndOneMover => "release:the-rk-pin-has-two-facts-and-one-mover",
124 DeliveredGateSetIsDeclaredOnce => "release:the-delivered-gate-set-is-declared-once",
125 ThirdPartyNoticesTravelWithThePayload => "release:third-party-notices-travel-with-the-payload",
126 VersionsAreSemanticAndAligned => "release:versions-are-semantic-and-aligned",
127 CommentCitesTheRule => "spec-to-code:a-comment-cites-the-rule",
128 CommentNamesNoRecord => "spec-to-code:a-comment-names-no-record",
129 GateMessageCitesTheRule => "spec-to-code:a-gate-message-cites-the-rule",
130 SpecChangeIsTyped => "spec-to-code:a-spec-change-is-typed",
131 SpecMayLeadItsCode => "spec-to-code:a-spec-may-lead-its-code",
132 SuppressionNamesItsCase => "spec-to-code:a-suppression-names-its-case",
133 EntryDocumentCitesRuleIds => "spec-to-code:an-entry-document-cites-rule-ids",
134 UnenactedRulesAreTheBacklog => "spec-to-code:unenacted-rules-are-the-backlog",
135 DeclaredDependentExists => "tracking:a-declared-dependent-exists",
136 PerishableSourceIsRegistered => "tracking:a-perishable-source-is-registered",
137 EntryDeclaresHowToRevalidate => "tracking:an-entry-declares-how-to-revalidate",
138 OverdueEntryBlocks => "tracking:an-overdue-entry-blocks",
139 UpstreamCheckDoesNotEditTheTree => "tracking:an-upstream-check-does-not-edit-the-tree",
140 UpstreamDerivationPinsARevision => "tracking:an-upstream-derivation-pins-a-revision",
141 RegistryHasOneReadableShape => "tracking:the-registry-has-one-readable-shape",
142 ExistingDocumentConvertsWhenEdited => "writing-style:an-existing-document-converts-when-edited",
143 NoDeliveredGateJudgesProse => "writing-style:no-delivered-gate-judges-prose",
144 SourcesNameTheRevisionRead => "writing-style:sources-name-the-revision-read",
145 DocumentationBlockRoutesToTheStyle => "writing-style:the-documentation-block-routes-to-the-style",
146 StyleLivesInOneDocument => "writing-style:the-style-lives-in-one-document",
147}
148
149impl fmt::Display for RuleId {
150 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
151 f.write_str(self.as_str())
152 }
153}
154
155#[cfg(test)]
156mod tests {
157 use super::*;
158
159 #[test]
160 fn slugs_are_well_formed_and_unique() {
161 let mut seen = std::collections::BTreeSet::new();
162 for rule in RuleId::ALL {
163 let id = rule.as_str();
164 let (domain, name) = id.split_once(':').unwrap();
165 let assert_slug = |part: &str| {
166 assert!(!part.is_empty(), "{id} has an empty half");
167 assert!(
168 part.bytes()
169 .all(|b| b.is_ascii_lowercase() || b.is_ascii_digit() || b == b'-'),
170 "{id} is not a slug pair"
171 );
172 };
173 assert_slug(domain);
174 assert_slug(name);
175 assert!(seen.insert(id), "{id} is duplicated");
176 }
177 }
178
179 #[test]
180 fn display_renders_the_slug_pair() {
181 assert_eq!(
182 RuleId::ChapterStaysWithinLineCap.to_string(),
183 "docs-format:chapter-stays-within-200-lines"
184 );
185 }
186}