From 3c3781ca4385c5e5d2a4b1407f452567f03c228e Mon Sep 17 00:00:00 2001 From: Lidang-Jiang Date: Sun, 29 Mar 2026 10:09:02 +0800 Subject: [PATCH] refactor: address reviewer feedback - Add options={} parameter to run() to match run-with-flags.js contract - Remove case-insensitive flag from extension pre-filter for consistency with ADHOC_FILENAMES regex (both now case-sensitive) - Expand warning text to list more structured paths - Add test cases for uppercase extensions (TODO.MD, NOTES.TXT) Co-Authored-By: Claude Opus 4.6 (1M context) Signed-off-by: Lidang-Jiang --- scripts/hooks/doc-file-warning.js | 8 ++++---- tests/hooks/doc-file-warning.test.js | 4 +++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/scripts/hooks/doc-file-warning.js b/scripts/hooks/doc-file-warning.js index b0f3eea3..ea685e25 100644 --- a/scripts/hooks/doc-file-warning.js +++ b/scripts/hooks/doc-file-warning.js @@ -28,8 +28,8 @@ function isSuspiciousDocPath(filePath) { const normalized = filePath.replace(/\\/g, '/'); const basename = path.basename(normalized); - // Only inspect .md and .txt files - if (!/\.(md|txt)$/i.test(basename)) return false; + // Only inspect .md and .txt files (case-sensitive, consistent with ADHOC_FILENAMES) + if (!/\.(md|txt)$/.test(basename)) return false; // Only flag known ad-hoc filenames if (!ADHOC_FILENAMES.test(basename)) return false; @@ -44,7 +44,7 @@ function isSuspiciousDocPath(filePath) { * Exportable run() for in-process execution via run-with-flags.js. * Avoids the ~50-100ms spawnSync overhead when available. */ -function run(inputOrRaw) { +function run(inputOrRaw, options = {}) { let input; try { input = typeof inputOrRaw === 'string' @@ -61,7 +61,7 @@ function run(inputOrRaw) { stderr: '[Hook] WARNING: Ad-hoc documentation filename detected\n' + `[Hook] File: ${filePath}\n` + - '[Hook] Consider using structured paths: docs/, .claude/commands/, skills/', + '[Hook] Consider using a structured path (e.g. docs/, .claude/, skills/, .github/, benchmarks/, templates/)', }; } diff --git a/tests/hooks/doc-file-warning.test.js b/tests/hooks/doc-file-warning.test.js index fc492145..9d966634 100644 --- a/tests/hooks/doc-file-warning.test.js +++ b/tests/hooks/doc-file-warning.test.js @@ -102,7 +102,7 @@ function runTests() { }) ? passed++ : failed++); } - // 5. Lowercase and partial-match filenames - NOT on denylist, no warning + // 5. Lowercase, partial-match, and non-standard extension case - NOT on denylist const allowedNonDenylist = [ 'random-notes.md', 'notes.txt', @@ -111,6 +111,8 @@ function runTests() { 'todo-list.md', 'my-draft.md', 'meeting-notes.txt', + 'TODO.MD', + 'NOTES.TXT', ]; for (const file of allowedNonDenylist) { (test(`allows non-denylist doc file: ${file}`, () => {