Skip to content

Commit dfdc208

Browse files
committed
fix(hooks): restore Linear issue reference check dropped during .mts refactor
1 parent 1e30641 commit dfdc208

2 files changed

Lines changed: 46 additions & 1 deletion

File tree

.git-hooks/_helpers.mts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,34 @@ export const scanNpxDlx = (text: string): LineHit[] => {
198198
return hits
199199
}
200200

201+
// ── Linear issue reference scanner ─────────────────────────────────
202+
// CLAUDE.md "ABSOLUTE RULES": NEVER reference Linear issues in commits.
203+
// Team keys enumerated from the Socket workspace. PATCH listed before
204+
// PAT so the alternation matches the longer prefix first.
205+
206+
const LINEAR_TEAM_KEYS =
207+
'ASK|AUTO|BOT|CE|CORE|DAT|DES|DEV|ENG|INFRA|LAB|MAR|MET|OPS|PAR|PATCH|PAT|PLAT|REA|SALES|SBOM|SEC|SMO|SUP|TES|TI|WEB'
208+
209+
const LINEAR_ISSUE_RE = new RegExp(
210+
`(?:^|[^A-Za-z0-9_])((?:${LINEAR_TEAM_KEYS})-[0-9]+)(?:$|[^A-Za-z0-9_])`,
211+
'gm',
212+
)
213+
214+
const LINEAR_URL_RE = /linear\.app\/[A-Za-z0-9/_-]+/g
215+
216+
export const scanLinearReferences = (commitMsg: string): string[] => {
217+
const hits: string[] = []
218+
const lines = commitMsg.split('\n').filter(l => !l.startsWith('#'))
219+
const body = lines.join('\n')
220+
for (const m of body.matchAll(LINEAR_ISSUE_RE)) {
221+
hits.push(m[1]!)
222+
}
223+
for (const m of body.matchAll(LINEAR_URL_RE)) {
224+
hits.push(m[0]!)
225+
}
226+
return hits.slice(0, 5)
227+
}
228+
201229
// ── AI attribution scanner ─────────────────────────────────────────
202230

203231
const AI_ATTRIBUTION_RE =

.git-hooks/commit-msg.mts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
out,
2424
red,
2525
readFileForScan,
26+
scanLinearReferences,
2627
scanSocketApiKeys,
2728
shouldSkipFile,
2829
stripAiAttribution,
@@ -67,10 +68,26 @@ const main = (): number => {
6768
}
6869
}
6970

70-
// Auto-strip AI attribution lines from the commit message.
7171
const commitMsgFile = process.argv[2]
7272
if (commitMsgFile && existsSync(commitMsgFile)) {
7373
const original = readFileSync(commitMsgFile, 'utf8')
74+
75+
// Block Linear issue references in the commit message.
76+
const linearHits = scanLinearReferences(original)
77+
if (linearHits.length) {
78+
out(red('✗ Commit message references Linear issue(s):'))
79+
for (const hit of linearHits) {
80+
out(` ${hit}`)
81+
}
82+
out(
83+
red(
84+
'Linear tracking lives in Linear. Remove the reference from the commit message.',
85+
),
86+
)
87+
errors++
88+
}
89+
90+
// Auto-strip AI attribution lines from the commit message.
7491
const { cleaned, removed } = stripAiAttribution(original)
7592
if (removed > 0) {
7693
writeFileSync(commitMsgFile, cleaned)

0 commit comments

Comments
 (0)