Skip to content
Merged
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
4 changes: 2 additions & 2 deletions .agents/scripts/pulse-wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1305,9 +1305,9 @@ _quality_sweep_for_repo() {
result=$(shellcheck -f gcc "$shfile" 2>/dev/null || true)
if [[ -n "$result" ]]; then
local file_errors
file_errors=$(echo "$result" | grep -c ':.*: error:' || echo "0")
file_errors=$(echo "$result" | grep -c ':.*: error:') || file_errors=0
local file_warnings
file_warnings=$(echo "$result" | grep -c ':.*: warning:' || echo "0")
file_warnings=$(echo "$result" | grep -c ':.*: warning:') || file_warnings=0
Comment on lines +1308 to +1310
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

While the fix is correct, for better performance and to adhere to modern shell scripting best practices, consider using a here-string (<<<) to pass the variable to grep. This avoids creating an extra subshell for echo and can be more efficient, especially if this script is run in a loop over many files. Additionally, for consistency and adherence to best practices, the local declaration for file_warnings has been separated from its assignment, as command substitution is involved.

Suggested change
file_errors=$(echo "$result" | grep -c ':.*: error:') || file_errors=0
local file_warnings
file_warnings=$(echo "$result" | grep -c ':.*: warning:' || echo "0")
file_warnings=$(echo "$result" | grep -c ':.*: warning:') || file_warnings=0
file_errors=$(grep -c ':.*: error:' <<< "$result") || file_errors=0
local file_warnings
file_warnings=$(grep -c ':.*: warning:' <<< "$result") || file_warnings=0
References
  1. When declaring and assigning local variables in shell scripts, separate the local declaration from the assignment if command substitution is involved, to ensure exit code safety. For consistency, this pattern should be maintained even for simple assignments.

sc_errors=$((sc_errors + file_errors))
sc_warnings=$((sc_warnings + file_warnings))

Expand Down
Loading