Skip to content

Commit 56272bc

Browse files
committed
chore(sync): cascade socket-hook marker fix from socket-repo-template
Pre-commit/pre-push scanners and the logger-guard hook now recognize `//` and `/* */` comment prefixes in addition to `#`, so `.ts`/`.mts` files can use `// socket-hook: allow logger` naturally.
1 parent 0f17dd1 commit 56272bc

3 files changed

Lines changed: 39 additions & 5 deletions

File tree

.claude/hooks/logger-guard/index.mts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,11 @@ const LOGGER_LEAK_RE =
6868

6969
const COMMENT_LINE_RE = /^\s*(\*|\/\/|#)/
7070
const JSDOC_TAG_RE = /@(example|param|returns?|see|link)\b/
71-
const SOCKET_HOOK_MARKER_RE = /#\s*socket-hook:\s*allow(?:\s+([\w-]+))?/
71+
// Accept `#`, `//`, or `/*` comment prefixes — same as the git pre-
72+
// commit/pre-push scanners. This hook is invoked on TS/JS edits where
73+
// `// socket-hook: allow logger` is the only natural spelling.
74+
const SOCKET_HOOK_MARKER_RE =
75+
/(?:#|\/\/|\/\*)\s*socket-hook:\s*allow(?:\s+([\w-]+))?/
7276

7377
function isMarkerSuppressed(line: string): boolean {
7478
const m = line.match(SOCKET_HOOK_MARKER_RE)

.claude/hooks/logger-guard/test/logger-guard.test.mts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,28 @@ test('respects bare # socket-hook: allow marker', async () => {
115115
assert.equal(code, 0)
116116
})
117117

118+
test('respects // socket-hook: allow logger marker (slash-slash prefix)', async () => {
119+
const { code } = await runHook({
120+
tool_name: 'Edit',
121+
tool_input: {
122+
file_path: 'src/foo.ts',
123+
new_string: 'process.stderr.write(buf) // socket-hook: allow logger',
124+
},
125+
})
126+
assert.equal(code, 0)
127+
})
128+
129+
test('respects /* socket-hook: allow logger */ marker (block-comment prefix)', async () => {
130+
const { code } = await runHook({
131+
tool_name: 'Edit',
132+
tool_input: {
133+
file_path: 'src/foo.ts',
134+
new_string: 'console.error("a") /* socket-hook: allow logger */',
135+
},
136+
})
137+
assert.equal(code, 0)
138+
})
139+
118140
test('does not flag JSDoc examples', async () => {
119141
const { code } = await runHook({
120142
tool_name: 'Write',

.git-hooks/_helpers.mts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,15 @@ const PERSONAL_PATH_PLACEHOLDER_RE =
102102

103103
// Per-line opt-out marker for our pre-commit / pre-push scanners.
104104
//
105-
// Canonical form: # socket-hook: allow
106-
// Targeted form: # socket-hook: allow <rule>
105+
// Canonical form: <comment-prefix> socket-hook: allow
106+
// Targeted form: <comment-prefix> socket-hook: allow <rule>
107+
//
108+
// `<comment-prefix>` is whichever comment style the host file uses —
109+
// `#` for shell / YAML / TOML / Dockerfile, `//` for TS / JS / Rust /
110+
// Go / C-family, or `/*` for the C-block-comment opener. The hook is
111+
// invoked from many file types; pinning to `#` made the marker fail
112+
// silently in `.ts` / `.mts` files (where `// socket-hook: allow` is
113+
// the only sensible spelling) and confused contributors.
107114
//
108115
// The targeted form names a specific rule (`personal-path`, `npx`,
109116
// `aws-key`, etc.) and is recommended for reviewers; the bare `allow`
@@ -113,8 +120,9 @@ const PERSONAL_PATH_PLACEHOLDER_RE =
113120
// Legacy `# zizmor: ...` markers are still recognized for one cycle so
114121
// existing files don't have to be rewritten in the same change that
115122
// renames the marker.
116-
const SOCKET_HOOK_MARKER_RE = /#\s*socket-hook:\s*allow(?:\s+([\w-]+))?/
117-
const LEGACY_ZIZMOR_MARKER_RE = /#\s*zizmor:\s*[\w-]+/
123+
const SOCKET_HOOK_MARKER_RE =
124+
/(?:#|\/\/|\/\*)\s*socket-hook:\s*allow(?:\s+([\w-]+))?/
125+
const LEGACY_ZIZMOR_MARKER_RE = /(?:#|\/\/|\/\*)\s*zizmor:\s*[\w-]+/
118126

119127
function lineIsSuppressed(line: string, rule?: string): boolean {
120128
if (LEGACY_ZIZMOR_MARKER_RE.test(line)) {

0 commit comments

Comments
 (0)