Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion content-guards/scripts/validate-markdown.sh
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,20 @@ EOF
fi
} 2>&1 ); then
errors+=("markdownlint-cli2 failed:")
errors+=("$markdownlint_output")
# Cap validator output so a noisy run can't flood Claude's context window.
# Single awk pass counts, caps, and formats the overflow footer.
max_lines=20
if [[ -n "$markdownlint_output" ]]; then
capped=$(awk -v max="$max_lines" '
NR <= max { print }
END {
if (NR > max) {
print "…and " (NR - max) " more line(s) (capped at " max "; rerun markdownlint-cli2 manually for the full report)"
}
}
' <<<"$markdownlint_output")
errors+=("$capped")
fi
Comment on lines +156 to +169
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

We can simplify this logic and avoid spawning awk twice (which is relatively expensive in shell scripts) by performing the line counting, capping, and footer formatting in a single awk invocation. This also avoids potential Bash arithmetic syntax errors if awk output is unexpected.

Suggested change
# Cap validator output so a noisy run can't flood Claude's context window.
max_lines=20
total_lines=$(awk 'END{print NR}' <<<"$markdownlint_output")
if (( total_lines > max_lines )); then
capped=$(awk -v max="$max_lines" 'NR<=max' <<<"$markdownlint_output")
capped+=$'\n…and '"$((total_lines - max_lines))"' more line(s) (capped at '"$max_lines"'; rerun markdownlint-cli2 manually for the full report)'
errors+=("$capped")
else
errors+=("$markdownlint_output")
fi
# Cap validator output so a noisy run can't flood Claude's context window.
max_lines=20
if [[ -n "$markdownlint_output" ]]; then
capped=$(awk -v max="$max_lines" '
NR <= max { print }
END {
if (NR > max) {
print "…and " (NR - max) " more line(s) (capped at " max "; rerun markdownlint-cli2 manually for the full report)"
}
}
' <<<"$markdownlint_output")
errors+=("$capped")
fi

fi
fi

Expand Down
Loading