From 1f2e6d4ce98ab8367fcd3a6637e044a822a31c39 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=82=A2=E3=83=AC=E3=82=AF=E3=82=B5=E3=83=B3=E3=83=80?= =?UTF-8?q?=E3=83=BC=2Eeth?= Date: Wed, 9 Oct 2024 08:36:33 +0900 Subject: [PATCH] chore: fix empty string checker to correctly count violations --- .github/empty-string-checker.ts | 35 +++++++++++++++------------------ 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/.github/empty-string-checker.ts b/.github/empty-string-checker.ts index 67b0894..5327f0e 100644 --- a/.github/empty-string-checker.ts +++ b/.github/empty-string-checker.ts @@ -87,32 +87,29 @@ function parseDiffForEmptyStrings(diff: string) { return; } - if (inHunk) { - if (line.startsWith("+++ b/")) { - currentFile = line.replace("+++ b/", ""); - return; - } + if (line.startsWith("--- a/") || line.startsWith("+++ b/")) { + currentFile = line.slice(6); + inHunk = false; + return; + } - if (line.startsWith("+") && !line.startsWith("+++")) { - if (line.includes('""')) { - violations.push({ - file: currentFile, - line: headLine, - content: line.substring(1), - }); - } - headLine++; - } else if (line.startsWith("-")) { - // Removed line; do not increment headLine - } else { - headLine++; + if (inHunk && line.startsWith("+")) { + // Check for various forms of empty strings, including at the start of the line + if (/^\+.*?(?:=\s*["'`]{2}|["'`]\s*:\s*["'`]|:\s*["'`]{2})/.test(line)) { + violations.push({ + file: currentFile, + line: headLine, + content: line.substring(1).trim(), + }); } + headLine++; + } else if (!line.startsWith("-")) { + headLine++; } }); return violations; } - main().catch((error) => { core.setFailed(`Error running empty string check: ${error instanceof Error ? error.message : String(error)}`); });