mirror of
https://github.com/wshobson/agents.git
synced 2026-03-18 09:37:15 +00:00
style: format all files with prettier
This commit is contained in:
@@ -21,6 +21,7 @@ Comprehensive guidance for writing production-ready Bash scripts using defensive
|
||||
## Core Defensive Principles
|
||||
|
||||
### 1. Strict Mode
|
||||
|
||||
Enable bash strict mode at the start of every script to catch errors early.
|
||||
|
||||
```bash
|
||||
@@ -29,12 +30,14 @@ set -Eeuo pipefail # Exit on error, unset variables, pipe failures
|
||||
```
|
||||
|
||||
**Key flags:**
|
||||
|
||||
- `set -E`: Inherit ERR trap in functions
|
||||
- `set -e`: Exit on any error (command returns non-zero)
|
||||
- `set -u`: Exit on undefined variable reference
|
||||
- `set -o pipefail`: Pipe fails if any command fails (not just last)
|
||||
|
||||
### 2. Error Trapping and Cleanup
|
||||
|
||||
Implement proper cleanup on script exit or error.
|
||||
|
||||
```bash
|
||||
@@ -49,6 +52,7 @@ TMPDIR=$(mktemp -d)
|
||||
```
|
||||
|
||||
### 3. Variable Safety
|
||||
|
||||
Always quote variables to prevent word splitting and globbing issues.
|
||||
|
||||
```bash
|
||||
@@ -63,6 +67,7 @@ cp "$source" "$dest"
|
||||
```
|
||||
|
||||
### 4. Array Handling
|
||||
|
||||
Use arrays safely for complex data handling.
|
||||
|
||||
```bash
|
||||
@@ -79,6 +84,7 @@ readarray -t numbers < <(seq 1 10)
|
||||
```
|
||||
|
||||
### 5. Conditional Safety
|
||||
|
||||
Use `[[ ]]` for Bash-specific features, `[ ]` for POSIX.
|
||||
|
||||
```bash
|
||||
@@ -513,7 +519,7 @@ check_dependencies
|
||||
|
||||
1. **Always use strict mode** - `set -Eeuo pipefail`
|
||||
2. **Quote all variables** - `"$variable"` prevents word splitting
|
||||
3. **Use [[ ]] conditionals** - More robust than [ ]
|
||||
3. **Use [[]] conditionals** - More robust than [ ]
|
||||
4. **Implement error trapping** - Catch and handle errors gracefully
|
||||
5. **Validate all inputs** - Check file existence, permissions, formats
|
||||
6. **Use functions for reusability** - Prefix with meaningful names
|
||||
|
||||
@@ -23,6 +23,7 @@ Comprehensive guidance for writing comprehensive unit tests for shell scripts us
|
||||
### What is Bats?
|
||||
|
||||
Bats (Bash Automated Testing System) is a TAP (Test Anything Protocol) compliant testing framework for shell scripts that provides:
|
||||
|
||||
- Simple, natural test syntax
|
||||
- TAP output format compatible with CI systems
|
||||
- Fixtures and setup/teardown support
|
||||
|
||||
@@ -23,6 +23,7 @@ Comprehensive guidance for configuring and using ShellCheck to improve shell scr
|
||||
### What is ShellCheck?
|
||||
|
||||
ShellCheck is a static analysis tool that analyzes shell scripts and detects problematic patterns. It supports:
|
||||
|
||||
- Bash, sh, dash, ksh, and other POSIX shells
|
||||
- Over 100 different warnings and errors
|
||||
- Configuration for target shell and flags
|
||||
@@ -82,6 +83,7 @@ export SHELLCHECK_CONFIG=~/.shellcheckrc
|
||||
## Common ShellCheck Error Codes
|
||||
|
||||
### SC1000-1099: Parser Errors
|
||||
|
||||
```bash
|
||||
# SC1004: Backslash continuation not followed by newline
|
||||
echo hello\
|
||||
|
||||
Reference in New Issue
Block a user