You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit bfb5eb1
Browse filesBrowse the repository at this point in the historyBrowse files
feat: add stable rule IDs and a rules reference (#512)
* feat: add stable rule IDs and a rules reference
Every check that can report a failure now has a stable rule ID (CC001,
CC003, ...) plus a link to its documentation. IDs are assigned in the
catalog and attached centrally when rules are built, so new rules inherit
their identity automatically.
Rule IDs and docs links now appear in the default, compact, and JSON
output, giving users a durable handle to reference and look up.
Add docs/rules.rst documenting every rule, and a test that fails if a rule
ships without a corresponding entry in that page.
* ci: auto fixes from pre-commit.com hooks
* test: strengthen internal-entry assertion and document full output
Assert unconditionally that the ignore_authors catalog entry and its built
rule carry no rule ID; the previous conditional guard let the test pass
vacuously if the rule were never built.
Show the complete default output in the rules reference, including the
Docs link, and document the compact form alongside it.
* perf: derive rule identity from the catalog instead of copying it
Attaching the rule ID with dataclasses.replace() rebuilt every rule on each
build_all_rules() call, roughly doubling its cost (19us -> 41us) and showing
up as a broad benchmark regression.
Expose rule_id and docs_url as properties backed by a check-name lookup into
the catalog. Identity still lives in one place, so rules cannot carry a stale
copy, and building them no longer does extra work. Add a test asserting the
lookup's key assumption that identified check names are unique.
* docs: point rule links at the documentation domain
Rule IDs print a link to their reference section, and that link ships in
terminal output and JSON results. Settle it on the project's own domain
before the first release that carries it, so the URLs do not need
redirecting later.
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
"""Human-readable rule name, e.g. ``subject-imperative``."""
38
+
returnself.check.replace("_", "-")
39
+
40
+
@property
41
+
defdocs_url(self) ->str|None:
42
+
"""Link to this rule's section in the rules reference, if it has an ID."""
43
+
ifnotself.rule_id:
44
+
returnNone
45
+
returnf"{RULES_DOCS_URL}#{self.rule_id.lower()}"
13
46
14
47
15
48
# Commit message rules
16
49
COMMIT_RULES= [
17
50
RuleCatalogEntry(
51
+
rule_id="CC001",
18
52
check="message",
19
53
regex=None, # Built dynamically from config
20
54
error="The commit message should follow Conventional Commits. See https://www.conventionalcommits.org",
21
55
suggest="Use <type>(<scope>): <description> with allowed types",
22
56
),
23
57
RuleCatalogEntry(
58
+
rule_id="CC002",
24
59
check="subject_capitalized",
25
60
regex=None,
26
61
error="Subject must start with a capital letter",
27
62
suggest="Capitalize the first word of the subject",
28
63
),
29
64
RuleCatalogEntry(
65
+
rule_id="CC003",
30
66
check="subject_imperative",
31
67
regex=None,
32
68
error="Commit message should use imperative mood (e.g., 'fix bug' not 'fixed bug', 'add feature' not 'adding feature')",
33
69
suggest="Change the first verb to imperative form, e.g., 'fix' instead of 'fixed'/'fixes'/'fixing'",
34
70
),
35
71
RuleCatalogEntry(
72
+
rule_id="CC004",
36
73
check="subject_max_length",
37
74
regex=None,
38
75
error="Subject must be at most {max_len} characters",
39
76
suggest="Keep the subject concise (<= configured max)",
40
77
),
41
78
RuleCatalogEntry(
79
+
rule_id="CC005",
42
80
check="subject_min_length",
43
81
regex=None,
44
82
error="Subject must be at least {min_len} characters",
45
83
suggest="Provide a meaningful subject (>= configured min)",
46
84
),
47
85
RuleCatalogEntry(
86
+
rule_id="CC006",
48
87
check="allow_merge_commits",
49
88
regex=None,
50
89
error="Merge commits are not allowed",
51
90
suggest="Rebase or squash your changes instead of merging",
52
91
),
53
92
RuleCatalogEntry(
93
+
rule_id="CC007",
54
94
check="allow_revert_commits",
55
95
regex=None,
56
96
error="Revert commits are not allowed",
57
97
suggest="Avoid using 'revert' commits; rewrite history if necessary",
58
98
),
59
99
RuleCatalogEntry(
100
+
rule_id="CC008",
60
101
check="allow_empty_commits",
61
102
regex=None,
62
103
error="Empty commit messages are not allowed",
63
104
suggest="Provide a non-empty subject",
64
105
),
65
106
RuleCatalogEntry(
107
+
rule_id="CC009",
66
108
check="allow_fixup_commits",
67
109
regex=None,
68
110
error="Fixup commits are not allowed",
69
111
suggest="Use interactive rebase to clean up fixup commits",
70
112
),
71
113
RuleCatalogEntry(
114
+
rule_id="CC010",
72
115
check="allow_wip_commits",
73
116
regex=None,
74
117
error="WIP commits are not allowed",
75
118
suggest="Complete the work before committing or remove 'WIP'",
# Internal bookkeeping entry - never produces a diagnostic.
96
143
check="ignore_authors",
97
144
regex=None,
98
145
error=None,
99
146
suggest=None,
100
147
),
101
148
RuleCatalogEntry(
149
+
rule_id="CC012",
102
150
check="require_signed_off_by",
103
151
regex=r"Signed-off-by: .+ <.+@.+>",
104
152
error="Signed-off-by not found in latest commit",
105
153
suggest="git commit --amend --signoff or use --signoff on commit",
106
154
),
107
155
RuleCatalogEntry(
156
+
rule_id="CC013",
108
157
check="ai_attribution",
109
158
regex=None,
110
159
error="AI attribution policy violation",
@@ -115,6 +164,7 @@ class RuleCatalogEntry:
115
164
# Push rules
116
165
PUSH_RULES= [
117
166
RuleCatalogEntry(
167
+
rule_id="CC301",
118
168
check="no_force_push",
119
169
regex=None,
120
170
error="Force push is not allowed",
@@ -125,21 +175,35 @@ class RuleCatalogEntry:
125
175
# Branch rules
126
176
BRANCH_RULES= [
127
177
RuleCatalogEntry(
178
+
rule_id="CC201",
128
179
check="branch",
129
180
regex=None, # Built dynamically from config
130
181
error="The branch should follow Conventional Branch. See https://conventionalbranch.org",
131
182
suggest="Use <type>/<description> with allowed types or add branch name to allow_branch_names in config, or use ignore_authors in config branch section to bypass",
132
183
),
133
184
RuleCatalogEntry(
185
+
rule_id="CC202",
134
186
check="merge_base",
135
187
regex=None, # Provided by config
136
188
error="Current branch is not rebased onto target branch",
137
189
suggest="Rebase or merge with the target branch",
138
190
),
139
191
RuleCatalogEntry(
192
+
# Internal bookkeeping entry - never produces a diagnostic.
140
193
check="ignore_authors",
141
194
regex=None,
142
195
error=None,
143
196
suggest=None,
144
197
),
145
198
]
199
+
200
+
#: All catalog entries that represent a user-facing, documented rule.
0 commit comments