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