From 54ad290a82cc63ca3fc254e1eceacdf3affed9b8 Mon Sep 17 00:00:00 2001 From: lachtan Date: Sun, 15 Mar 2026 15:43:08 +0100 Subject: [PATCH] Add resource cleanup and structured data rules to bash style guide --- .claude/rules/bash-style.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/.claude/rules/bash-style.md b/.claude/rules/bash-style.md index 3227323..36c50b3 100644 --- a/.claude/rules/bash-style.md +++ b/.claude/rules/bash-style.md @@ -20,7 +20,7 @@ Complements CLAUDE.md. Does not repeat rules already defined there. ## 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 - `verb_noun` pattern for functions: `set_ps1_prompt`, `docker_aws_login` - 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 - `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 - Long options for clarity: `--recursive` not `-r` (common test flags `-f`, `-d`, `-e` are fine)