This document defines the coding standards for all Crucible source files. All contributors and AI-assisted sessions must follow these conventions.
- Shebang:
#!/usr/bin/env bash - Set options:
set -euo pipefailat the top of every file - Indentation: 4 spaces (per .editorconfig)
- Line length: 100 characters soft limit, 120 hard limit
- Quoting: Always double-quote variables unless word splitting is intentional
- Functions:
snake_case— prefixed by module name (e.g.,tui_menu(),detect_distro(),state_save()) - Local variables:
snake_case, declared withlocal - Global/exported variables:
UPPER_SNAKE_CASE, prefixed withCRUCIBLE_(e.g.,CRUCIBLE_DIR,CRUCIBLE_VERSION) - Constants:
readonly UPPER_SNAKE_CASE - File names:
kebab-case.shfor lib files,test_<module>.batsfor tests (e.g.,test_detect.bats)
Every public function gets a comment block:
# Brief description of what the function does.
#
# Arguments:
# $1 — description (type)
# $2 — description (type)
#
# Returns:
# 0 on success, 1 on failure
# Outputs: description of stdout output (if any)
#
# @since 0.1.0
function_name() {- Functions return 0 for success, non-zero for failure
- Error messages go to stderr:
echo "Error: message" >&2 - Fatal errors use a common
die()function (defined in the entrypoint or a common lib) - Never silently swallow errors — no empty catch blocks, no
|| truewithout a comment explaining why
Every .sh file starts with:
#!/usr/bin/env bash
# Crucible — [component description]
# Copyright (c) 2025 Marc Mironescu <marcm@fluxgear.io>
# SPDX-License-Identifier: MIT
# https://github.com/fluxgear/crucible- Source paths relative to
CRUCIBLE_DIR(resolved by the entrypoint) - Source guard pattern to prevent double-sourcing:
[[ -n "${_CRUCIBLE_TUI_LOADED:-}" ]] && return 0
readonly _CRUCIBLE_TUI_LOADED=1# SECURITY:comment prefix on security-critical code- All user input validated before use
- No
eval, no unquoted command substitution with user data - Temp files created with
mktempin controlled directories
- BATS test files in
tests/ - Test file naming:
test_<module>.bats(e.g.,test_detect.bats) - Shared setup in
tests/test_helper.bash - Each test function prefixed with
@test - Tests must be self-contained — no dependency on system state
<type>(<scope>): <short summary> with detailed body.
Types: feat, fix, docs, refactor, style, test, chore, security
Scopes: foundation, tui, detect, state, install, provision, webapp, harden, docker, test, system