Skip to content

fix: grep -c arithmetic error in quality sweep ShellCheck section#2637

Merged
marcusquinn merged 1 commit intomainfrom
bugfix/grep-count
Mar 1, 2026
Merged

fix: grep -c arithmetic error in quality sweep ShellCheck section#2637
marcusquinn merged 1 commit intomainfrom
bugfix/grep-count

Conversation

@marcusquinn
Copy link
Owner

@marcusquinn marcusquinn commented Mar 1, 2026

Summary

  • Fixes syntax error in expression (error token is "0\n0") that prevented the daily quality sweep from completing
  • Root cause: grep -c outputs 0 on no match AND exits 1. With || echo "0", output becomes 0\n0 (two lines) which fails in $(( )) arithmetic
  • Fix: file_errors=$(... | grep -c ...) || file_errors=0 — the fallback assigns directly instead of appending to stdout

Summary by CodeRabbit

  • Refactor
    • Enhanced shell script linting result detection and processing for more consistent error and warning identification.

grep -c outputs '0' on no match AND exits 1. The || echo '0' then
appends a second '0', giving '0\n0' which fails in $(( )).
Fix: use || var=0 as a separate statement instead of piped fallback.
@marcusquinn marcusquinn merged commit bd3225e into main Mar 1, 2026
13 of 15 checks passed
@marcusquinn marcusquinn deleted the bugfix/grep-count branch March 1, 2026 04:42
@github-actions github-actions bot added the bug Auto-created from TODO.md tag label Mar 1, 2026
@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical bug in the daily quality sweep script that was causing it to fail due to an arithmetic syntax error. The change modifies how the count of ShellCheck errors and warnings is handled when grep -c returns no matches, ensuring that the script correctly processes zero counts without generating invalid input for arithmetic operations. This ensures the stability and proper functioning of the quality sweep.

Highlights

  • Error Fix: Resolved a syntax error in expression (error token is "0\n0") that was preventing the daily quality sweep from completing.
  • Root Cause Identified: The issue stemmed from grep -c outputting 0 and exiting with status 1 on no match, which, when combined with || echo "0", resulted in a 0\n0 string that caused arithmetic errors in $(( )).
  • Correction Implemented: The fix involves directly assigning 0 to file_errors or file_warnings when grep -c fails, instead of appending 0 to its output via a pipe.
Changelog
  • .agents/scripts/pulse-wrapper.sh
    • Modified the assignment logic for file_errors and file_warnings to correctly handle cases where grep -c returns no matches, preventing arithmetic errors.
Activity
  • No human activity has been recorded on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 1, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e1db8f0 and cb8932a.

📒 Files selected for processing (1)
  • .agents/scripts/pulse-wrapper.sh

Walkthrough

Modified ShellCheck finding counting in the pulse-wrapper script by adjusting the grep pattern's capitalization and spacing, and relocated the default-fallback logic from an inline echo to an explicit shell-guarded assignment for improved default value handling.

Changes

Cohort / File(s) Summary
ShellCheck Counting Logic
.agents/scripts/pulse-wrapper.sh
Adjusted grep pattern formatting and relocated default-fallback handling from inline echo to explicit assignment, improving how error and warning counts are captured when grep patterns don't match.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly related PRs

  • fix: sanity-check grep -c arithmetic errors #2280 — Addresses the same grep-count-to-integer safety issue in sanity-check.sh by trimming whitespace from grep -c outputs; complementary fix for consistent grep result handling across shell scripts.

Poem

A grep pattern tweak, clean and bright,
Default assignments set just right,
No more slips in arithmetic's dance—
Shell scripts blessed with one more glance! 🎭✨

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch bugfix/grep-count

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link

github-actions bot commented Mar 1, 2026

🔍 Code Quality Report

�[0;35m[MONITOR]�[0m Code Review Monitoring Report

�[0;34m[INFO]�[0m Latest Quality Status:
SonarCloud: 0 bugs, 0 vulnerabilities, 109 code smells

�[0;34m[INFO]�[0m Recent monitoring activity:
Sun Mar 1 04:42:32 UTC 2026: Code review monitoring started
Sun Mar 1 04:42:33 UTC 2026: SonarCloud - Bugs: 0, Vulnerabilities: 0, Code Smells: 109

📈 Current Quality Metrics

  • BUGS: 0
  • CODE SMELLS: 109
  • VULNERABILITIES: 0

Generated on: Sun Mar 1 04:42:35 UTC 2026


Generated by AI DevOps Framework Code Review Monitoring

@sonarqubecloud
Copy link

sonarqubecloud bot commented Mar 1, 2026

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly fixes a bug in the quality sweep script where grep -c was causing an arithmetic error on no match. The change to use || var=0 is a robust way to handle the exit code of grep while set -e is active. I have a suggestion to improve the code further by using a here-string for efficiency and to separate the local declaration from assignment for file_warnings for consistency and safety.

Comment on lines +1308 to +1310
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

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Auto-created from TODO.md tag

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant