Add resource cleanup and structured data rules to bash style guide

This commit is contained in:
lachtan
2026-03-15 15:43:08 +01:00
parent f8a61e9290
commit 54ad290a82

View File

@@ -20,7 +20,7 @@ Complements CLAUDE.md. Does not repeat rules already defined there.
## Naming ## Naming
- `UPPER_CASE` — exported env vars and constants - `UPPER_CASE` — exported env vars and constants; use `readonly` for true constants
- `snake_case` — local variables and function names - `snake_case` — local variables and function names
- `verb_noun` pattern for functions: `set_ps1_prompt`, `docker_aws_login` - `verb_noun` pattern for functions: `set_ps1_prompt`, `docker_aws_login`
- Meaningful names, no single letters except loop counters (`i`, `f`) - Meaningful names, no single letters except loop counters (`i`, `f`)
@@ -51,6 +51,15 @@ function do_thing() {
- Single quotes for literals that must not expand - Single quotes for literals that must not expand
- `printf` over `echo` when output contains escapes or format strings - `printf` over `echo` when output contains escapes or format strings
## Resource Cleanup
- Consider `trap cleanup EXIT` with `mktemp` when scripts create temporary files/dirs or acquire resources; skip when it would add unnecessary complexity (short scripts, no temp state)
## Structured Data
- Prefer `jq` for JSON and `yq` for YAML over ad-hoc `grep`/`awk`/string splitting
- Treat parser errors as fatal; check exit status before using results
## Commands ## Commands
- Long options for clarity: `--recursive` not `-r` (common test flags `-f`, `-d`, `-e` are fine) - Long options for clarity: `--recursive` not `-r` (common test flags `-f`, `-d`, `-e` are fine)