Refactor shell scripts for improved safety and consistency; add guidelines to documentation

This commit is contained in:
GitHub Copilot
2025-05-07 13:54:02 +00:00
parent 3a9dc56559
commit 6f53b593d7
3 changed files with 136 additions and 45 deletions

View File

@@ -133,6 +133,31 @@ This project is a financial transaction management application built with Astro
## Code Style & Conventions
### Shell Scripts
All shell scripts should follow these conventions:
- Use `#!/usr/bin/env bash` instead of direct path to bash
- Include standard safety flags at the start of each script:
```bash
set -o errexit # Exit on error
set -o errtrace # Exit on error inside functions
set -o nounset # Error on undefined variables
set -o pipefail # Error if any command in a pipe fails
```
- Use `readonly` for constants and configuration values
- Write error messages to stderr using `>&2`
- Use proper error handling and exit codes
- Validate all required parameters and dependencies
- Use `[[` instead of `[` for better feature support
- Quote all variable expansions
- Use `${variable:-}` pattern for safe variable expansion
- Handle special characters in input properly
- Include clear error messages and validation
- Group configuration/constants at the top of the script
- Add descriptive comments for complex logic
- Follow consistent indentation and formatting
### Import Path Aliases
Always use the path aliases defined in `tsconfig.json` instead of relative imports. This makes the code more maintainable and easier to refactor.