Lint Analysis
Running bashrs lint on the ZSH widget reveals several issues:
Original Widget (v1)
Summary: 0 error(s), 2 warning(s), 6 info(s)
Score: B (7.5/10)
Fixed Widget (v2)
Summary: 0 error(s), 13 warning(s), 10 info(s)
Score: C+ (6.8/10)
The v2 widget actually has MORE warnings because it's more complex.
Key Issues
1. SC2046: Unquoted command substitution (word splitting risk)
# Current (vulnerable):
suggestion=$(timeout 0.1 aprender-shell suggest "$BUFFER" 2>/dev/null | head -1 | cut -f1)
# Fixed:
suggestion="$(timeout 0.1 aprender-shell suggest "$BUFFER" 2>/dev/null | head -1 | cut -f1)"
If aprender-shell suggest returns a string with spaces or special characters, word splitting could cause issues.
2. SC2086: Unquoted variable in comparison
# Current:
if [[ -n "$POSTDISPLAY" && $CURSOR -eq ${#BUFFER} ]]; then
# Fixed:
if [[ -n "$POSTDISPLAY" && "$CURSOR" -eq "${#BUFFER}" ]]; then
3. SC2148: Missing shebang
The widget should have a shebang for clarity:
#!/usr/bin/env zsh
# aprender-shell ZSH widget v2
4. SC2125/SC2201: Array assignment issues
# Current (confusing):
region_highlight=()
# Better (explicit):
local -a region_highlight
region_highlight=()
Note on False Positives
Some warnings are false positives for ZSH:
- SC2031 (subshell variable scope) - ZSH handles this differently
- SC2154 (APRENDER_DISABLED unassigned) - It's an environment variable
Recommended Improvements
#!/usr/bin/env zsh
# aprender-shell ZSH widget v2
# Toggle: export APRENDER_DISABLED=1 to disable
_aprender_suggest() {
[[ "$APRENDER_DISABLED" == "1" ]] && return
[[ "${#BUFFER}" -lt 2 ]] && { POSTDISPLAY=''; region_highlight=(); return; }
local suggestion
suggestion="$(timeout 0.1 aprender-shell suggest "$BUFFER" 2>/dev/null | head -1 | cut -f1)"
if [[ -n "$suggestion" && "$suggestion" != "$BUFFER" ]]; then
POSTDISPLAY=" ${suggestion#$BUFFER}"
region_highlight=("${#BUFFER} $((${#BUFFER} + ${#POSTDISPLAY})) fg=8")
else
POSTDISPLAY=''
region_highlight=()
fi
}
Related
Lint Analysis
Running
bashrs linton the ZSH widget reveals several issues:Original Widget (v1)
Fixed Widget (v2)
The v2 widget actually has MORE warnings because it's more complex.
Key Issues
1. SC2046: Unquoted command substitution (word splitting risk)
If
aprender-shell suggestreturns a string with spaces or special characters, word splitting could cause issues.2. SC2086: Unquoted variable in comparison
3. SC2148: Missing shebang
The widget should have a shebang for clarity:
4. SC2125/SC2201: Array assignment issues
Note on False Positives
Some warnings are false positives for ZSH:
Recommended Improvements
Related
bashrs lintandbashrs audit