You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Run shellcheck on all branches, fix all violations, and update documentation (#31)
* Initial plan
* Update GitHub Action to run shellcheck on every commit to all branches
Co-authored-by: lunarcloud <1565970+lunarcloud@users.noreply.github.com>
* Fix: Prevent duplicate workflow runs on PRs
Co-authored-by: lunarcloud <1565970+lunarcloud@users.noreply.github.com>
* Fix all shellcheck violations across the codebase
Co-authored-by: lunarcloud <1565970+lunarcloud@users.noreply.github.com>
* Update AGENTS.md to document new shellcheck and quoting requirements
Co-authored-by: lunarcloud <1565970+lunarcloud@users.noreply.github.com>
* Fix whiptail checklist showing usage text instead of TUI dialog
Remove quotes from conditional --scrolltext argument to prevent
empty string being passed as an argument when RECMD_SCROLL is false.
Added shellcheck directives to document intentional word splitting.
Co-authored-by: lunarcloud <1565970+lunarcloud@users.noreply.github.com>
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: lunarcloud <1565970+lunarcloud@users.noreply.github.com>
- Linux desktops: Detected via `$XDG_CURRENT_DESKTOP`, `$XDG_SESSION_DESKTOP`, or running processes via `pgrep -l "process-name"` (gnome-shell, mutter, kwin)
117
115
116
+
### Shellcheck Directives and Cross-File Variables
117
+
118
+
The library uses a modular structure where `init.sh` defines variables used across multiple files. To handle shellcheck warnings about these cross-file variables:
119
+
120
+
1.**For variables defined in init.sh and used elsewhere**:
121
+
- Add `# shellcheck disable=SC2154` at the top of files that use variables from init.sh
122
+
- This suppresses "variable is referenced but not assigned" warnings
123
+
124
+
2.**For variables exposed to library users**:
125
+
- Add `# shellcheck disable=SC2034` at the file level in init.sh
126
+
- This suppresses "variable appears unused" warnings for intentionally exposed variables
127
+
- Do NOT export these variables to avoid polluting the user's environment
- This prevents SC2046 warnings while maintaining correct behavior
132
+
133
+
Example:
134
+
```bash
135
+
# At the top of a file using init.sh variables
136
+
#!/usr/bin/env bash
137
+
# Multi-UI Scripting - Helper Functions
138
+
139
+
# Variables set in init.sh and used here
140
+
# shellcheck disable=SC2154
141
+
142
+
# Now you can use variables like $bold, $normal, $red without warnings
143
+
```
144
+
118
145
## Cross-Platform Considerations
119
146
120
147
### Platform-Specific Behavior
@@ -164,14 +191,22 @@ Use `screenshot-dialogs.sh` to capture visual evidence of changes:
164
191
165
192
### Automated Testing (CI)
166
193
167
-
The GitHub Actions workflow runs shellcheck on all `.sh` files. All code must pass shellcheck without errors.
194
+
The GitHub Actions workflow runs shellcheck on all `.sh` files for every PR and direct commit to master. All code must pass shellcheck without errors or warnings.
195
+
196
+
The workflow is configured to:
197
+
- Run on all pull requests (via `pull_request` trigger)
198
+
- Run on direct commits to `master` branch (via `push` trigger)
199
+
- Avoid duplicate runs on PRs by not triggering `push` for non-master branches
168
200
169
201
## Common Patterns and Pitfalls to Avoid
170
202
171
203
### DO:
172
204
* Capture exit status immediately after the command that generates it
173
205
* Use `|| exit "$?"` after command substitutions that might be cancelled
174
206
* Quote variable expansions: `"$variable"` not `$variable`
207
+
* Quote command substitutions: `"$(command)"` not `$(command)`
208
+
* Separate variable declarations from assignments: `local var; var=$(cmd)` not `local var=$(cmd)`
209
+
* Use shellcheck directives for cross-file variables instead of exporting them
175
210
* Test with multiple interfaces (zenity, kdialog, whiptail, dialog)
176
211
* Document why you're disabling shellcheck rules if necessary
177
212
* Consider both GUI and TUI behavior when implementing features
@@ -184,6 +219,8 @@ The GitHub Actions workflow runs shellcheck on all `.sh` files. All code must pa
184
219
* Remove or modify cancel detection without thorough testing
185
220
* Break backward compatibility with existing scripts
186
221
* Copy complex patterns from other projects without understanding them
222
+
* Export variables unnecessarily - use shellcheck directives instead to avoid environment pollution
223
+
* Leave unquoted variables or command substitutions that trigger shellcheck warnings
187
224
188
225
## Recent Learnings from PR Feedback
189
226
@@ -202,6 +239,21 @@ From PR #28 (Add configurable exit on dialog cancellation):
202
239
- It follows the `timeout` command convention (which also uses 124)
203
240
- It's less generic than 1 or 2
204
241
242
+
From PR (Shellcheck compliance and CI improvements):
243
+
244
+
1.**Quoting is mandatory**: All variable expansions and command substitutions must be quoted to pass shellcheck. This prevents word splitting and globbing issues.
245
+
246
+
2.**Separate declarations from assignments**: Using `local var=$(command)` masks the command's exit status. Always separate them: `local var; var=$(command)` followed by `exit_status=$?`.
247
+
248
+
3.**Use shellcheck directives, not exports**: When variables are defined in `init.sh` and used in other sourced files:
249
+
- Add `# shellcheck disable=SC2154` at the top of files using those variables
250
+
- Add `# shellcheck disable=SC2034` in init.sh for variables exposed to library users
251
+
- Do NOT export variables just to satisfy shellcheck - this pollutes the user's environment
252
+
253
+
4.**CI must catch issues early**: The GitHub Actions workflow now runs on all PRs and master commits, ensuring code quality before merge.
254
+
255
+
5.**Zero tolerance for shellcheck violations**: All code must pass `shellcheck ./*.sh extras/*.sh -x` with zero warnings or errors.
256
+
205
257
## Boundaries and Guardrails
206
258
207
259
***NEVER** add a feature only supported on one OS or desktop environment.
0 commit comments