Skip to content

Commit

Permalink
chore: fix empty string checker to correctly count violations
Browse files Browse the repository at this point in the history
  • Loading branch information
0x4007 committed Oct 8, 2024
1 parent a9b93e5 commit 1f2e6d4
Showing 1 changed file with 16 additions and 19 deletions.
35 changes: 16 additions & 19 deletions .github/empty-string-checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)}`);
});

0 comments on commit 1f2e6d4

Please sign in to comment.