-
Notifications
You must be signed in to change notification settings - Fork 8
t1323: Fix TTSR shell-local-params rule false-positives on currency/pricing text #2296
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1510,9 +1510,11 @@ const BUILTIN_TTSR_RULES = [ | |
| // Only match bare $N at the start of a line or after whitespace in what looks | ||
| // like a shell assignment/command context — avoids matching $1 inside prose, | ||
| // documentation, quoted examples, or tool output from file reads. | ||
| // Excludes currency/pricing patterns: $[1-9] followed by digits, decimal, comma, | ||
| // or slash (e.g. $28/mo, $1.99, $1,000) to prevent false-positives in markdown tables. | ||
| pattern: "^\\s+(?:echo|printf|return|if|\\[\\[).*\\$[1-9](?![0-9.,/])(?!.*local\\s+\\w+=)", | ||
| // Excludes currency/pricing patterns: | ||
| // - $[1-9] followed by digits, decimal, comma, or slash (e.g. $28/mo, $1.99, $1,000) | ||
| // - $[1-9] followed by pipe (markdown table cell boundary) | ||
| // - $[1-9] followed by common currency/pricing unit words (per, mo, month, flat, etc.) | ||
| pattern: "^\\s+(?:echo|printf|return|if|\\[\\[).*\\$[1-9](?![0-9.,/])(?!\\s*[|])(?!\\s+(?:per|mo(?:nth)?|year|yr|day|week|hr|hour|flat|each|off|fee|plan|tier|user|seat|unit|addon|setup|trial|credit|annual|quarterly|monthly)\\b)(?!.*local\\s+\\w+=)", | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The new Severity: medium Other Locations
🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage. |
||
| correction: "Use `local var=\"$1\"` pattern — never use positional parameters directly (SonarCloud S7679).", | ||
| severity: "warn", | ||
| systemPrompt: "Shell scripts: use `local var=\"$1\"` — never use $1 directly in function bodies.", | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -188,8 +188,12 @@ check_positional_parameters() { | |||||||
| /print.*\$[1-9]/ { next } | ||||||||
| /Usage:/ { next } | ||||||||
| # Skip currency/pricing patterns: $[1-9] followed by digit, decimal, comma, | ||||||||
| # or slash (e.g. $28/mo, $1.99, $1,000) — false-positives in markdown tables. | ||||||||
| # slash (e.g. $28/mo, $1.99, $1,000), pipe (markdown table), or common | ||||||||
| # currency/pricing unit words (per, mo, month, flat, etc.). | ||||||||
| /\$[1-9][0-9.,\/]/ { next } | ||||||||
| /\$[1-9][[:space:]]*\|/ { next } | ||||||||
| /\$[1-9][[:space:]]+(per|mo(nth)?|year|yr|day|week|hr|hour|flat|each|off|fee|plan|tier|user|seat|unit|addon|setup|trial|credit|annual|quarterly|monthly)[[:space:][:punct:]]/ { next } | ||||||||
| /\$[1-9][[:space:]]+(per|mo(nth)?|year|yr|day|week|hr|hour|flat|each|off|fee|plan|tier|user|seat|unit|addon|setup|trial|credit|annual|quarterly|monthly)$/ { next } | ||||||||
|
Comment on lines
+195
to
+196
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These two lines are nearly identical, with the only difference being the match at the end of the line (
Suggested change
|
||||||||
| in_func && /\$[1-9]/ && !/local.*=.*\$[1-9]/ { | ||||||||
| print FILENAME ":" NR ": " $0 | ||||||||
| } | ||||||||
|
|
||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -78,10 +78,11 @@ validate_positional_parameters() { | |||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| for file in "$@"; do | ||||||||||||||||||||||||||||||||
| # Exclude currency/pricing patterns: $[1-9] followed by digit, decimal, comma, | ||||||||||||||||||||||||||||||||
| # or slash (e.g. $28/mo, $1.99, $1,000) — false-positives in markdown tables. | ||||||||||||||||||||||||||||||||
| if [[ -f "$file" ]] && grep -n '\$[1-9]' "$file" | grep -v 'local.*=.*\$[1-9]' | grep -vE '\$[1-9][0-9.,/]' >/dev/null; then | ||||||||||||||||||||||||||||||||
| # slash (e.g. $28/mo, $1.99, $1,000), pipe (markdown table cell), or common | ||||||||||||||||||||||||||||||||
| # currency/pricing unit words (per, mo, month, flat, etc.). | ||||||||||||||||||||||||||||||||
| if [[ -f "$file" ]] && grep -n '\$[1-9]' "$file" | grep -v 'local.*=.*\$[1-9]' | grep -vE '\$[1-9][0-9.,/]' | grep -vE '\$[1-9]\s*\|' | grep -vE '\$[1-9]\s+(per|mo(nth)?|year|yr|day|week|hr|hour|flat|each|off|fee|plan|tier|user|seat|unit|addon|setup|trial|credit|annual|quarterly|monthly)\b' >/dev/null; then | ||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Severity: high Other Locations
🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage. |
||||||||||||||||||||||||||||||||
| print_error "Direct positional parameter usage in $file" | ||||||||||||||||||||||||||||||||
| grep -n '\$[1-9]' "$file" | grep -v 'local.*=.*\$[1-9]' | grep -vE '\$[1-9][0-9.,/]' | head -3 | ||||||||||||||||||||||||||||||||
| grep -n '\$[1-9]' "$file" | grep -v 'local.*=.*\$[1-9]' | grep -vE '\$[1-9][0-9.,/]' | grep -vE '\$[1-9]\s*\|' | grep -vE '\$[1-9]\s+(per|mo(nth)?|year|yr|day|week|hr|hour|flat|each|off|fee|plan|tier|user|seat|unit|addon|setup|trial|credit|annual|quarterly|monthly)\b' | head -3 | ||||||||||||||||||||||||||||||||
|
Comment on lines
+83
to
+85
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # First, find and read the pre-commit-hook.sh file
find . -name "pre-commit-hook.sh" -type fRepository: marcusquinn/aidevops Length of output: 100 🏁 Script executed: # Read the file around the reported lines
if [ -f ".agents/scripts/pre-commit-hook.sh" ]; then
wc -l ".agents/scripts/pre-commit-hook.sh"
fiRepository: marcusquinn/aidevops Length of output: 102 🏁 Script executed: # Get context around lines 80-85
if [ -f ".agents/scripts/pre-commit-hook.sh" ]; then
sed -n '75,90p' ".agents/scripts/pre-commit-hook.sh"
fiRepository: marcusquinn/aidevops Length of output: 1083 🌐 Web query:
💡 Result: On macOS’s default (BSD/Apple)
If you need portable ERE, use:
Also note: other macOS tools (notably Sources: 🏁 Script executed: # Check if ShellCheck is available and run it on the file
which shellcheck || echo "ShellCheck not available"
if command -v shellcheck &> /dev/null; then
shellcheck ".agents/scripts/pre-commit-hook.sh" || true
fiRepository: marcusquinn/aidevops Length of output: 149 🏁 Script executed: # Also check the specific lines for context and verify the duplication more clearly
sed -n '76,90p' ".agents/scripts/pre-commit-hook.sh" | cat -nRepository: marcusquinn/aidevops Length of output: 1168 Refactor the grep pipeline to eliminate duplication and improve readability, but note that While Extract the grep result into a variable to eliminate duplication: local matches
matches=$(grep -n '\$[1-9]' "$file" \
| grep -v 'local.*=.*\$[1-9]' \
| grep -vE '\$[1-9][0-9.,/]' \
| grep -vE '\$[1-9]\s*\|' \
| grep -vE '\$[1-9]\s+(per|mo(nth)?|year|yr|day|week|hr|hour|flat|each|off|fee|plan|tier|user|seat|unit|addon|setup|trial|credit|annual|quarterly|monthly)\b' \
|| true)
if [[ -f "$file" ]] && [[ -n "$matches" ]]; then
print_error "Direct positional parameter usage in $file"
echo "$matches" | head -3
((violations++))
fiThis also improves readability by breaking the long pipeline into logical sections. 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||
| ((violations++)) | ||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||
|
Comment on lines
+83
to
87
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The long
Suggested change
References
|
||||||||||||||||||||||||||||||||
| done | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For improved readability and maintainability of this complex regular expression, you can make it more concise by grouping related alternatives. For example,
year|yrcan be combined intoy(?:ea)?r, andhr|hourcan beh(?:ou)?r. This makes the pattern slightly shorter and easier to parse visually.