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 bbfb46f commit e7149c3
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions .github/empty-string-checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,20 +93,25 @@ function parseDiffForEmptyStrings(diff: string) {
return;
}

if (inHunk && line.startsWith("+")) {
// Ignore package.json version numbers and ternary expressions
if (currentFile.endsWith("package.json") || /\? .+ : .+/.test(line)) {
headLine++;
return;
}
// Only process TypeScript files
if (!currentFile.endsWith(".ts")) {
return;
}

// Check for various forms of empty strings, excluding version numbers and valid use cases
if (/^\+.*?(?:=\s*["'`]{2}(?!\s*[,;])|["'`]\s*:\s*["'`](?!\s*[,;])|:\s*["'`]{2}(?!\s*[,;]))/.test(line)) {
violations.push({
file: currentFile,
line: headLine,
content: line.substring(1).trim(),
});
if (inHunk && line.startsWith("+")) {
// Check for empty strings in TypeScript syntax
if (/^\+.*?(?:=\s*["'`]{2}(?!\s*[,;])|:\s*["'`]{2}(?!\s*[,;]))/.test(line)) {
// Ignore empty strings in comments
if (!line.trim().startsWith("//") && !line.trim().startsWith("*")) {
// Ignore empty strings in template literals
if (!/`[^`]*\$\{[^}]*\}[^`]*`/.test(line)) {
violations.push({
file: currentFile,
line: headLine,
content: line.substring(1).trim(),
});
}
}
}
headLine++;
} else if (!line.startsWith("-")) {
Expand Down

0 comments on commit e7149c3

Please sign in to comment.