Toolkit: shfmt, bats, check-jsonschema, ruff, Cobra & More
The lessons used the tools that ship with a typical Linux box plus jq, yq, ShellCheck and yamllint. This page lists the wider toolkit that teams around those tools use: formatters, test frameworks, linters and libraries for each of the three languages, and a single lint entry point that ties them together. Versions move quickly; check each project's releases before pinning.
Shell
| Tool | What it does | Typical use |
|---|---|---|
| ShellCheck | static analysis for sh/bash (lesson) | CI gate, editor plugin |
| shfmt | formatter and parser for shell scripts (shfmt -i 2 -ci -d . shows a diff) |
keeps style arguments out of reviews; -d fails CI on unformatted files |
| bats-core | test framework: @test "name" { run ./script; [ "$status" -eq 2 ]; } |
unit tests for scripts that matter |
| pre-commit | runs hooks (shellcheck, shfmt, yamllint, ruff, …) on staged files before each commit | the same checks locally and in CI |
GNU parallel / xargs -P |
run commands concurrently with a limit | fan-out jobs from the shell |
| gum | prompts, spinners and menus for interactive scripts | developer-facing helper scripts |
A bats test for the rotate script from Arguments, Usage and Exit Codes:
#!/usr/bin/env bats
setup() {
dir=$(mktemp -d)
touch "$dir"/db-2026-01-0{1..7}.sql.gz
}
teardown() { rm -rf "$dir"; }
@test "keeps the newest N files" {
run ./rotate --keep 3 "$dir"
[ "$status" -eq 0 ]
[ "$(ls "$dir" | wc -l)" -eq 3 ]
}
@test "rejects a non-numeric --keep with status 2" {
run ./rotate --keep three "$dir"
[ "$status" -eq 2 ]
[[ "$output" == *"must be a number"* ]]
}JSON and YAML
| Tool | What it does |
|---|---|
| jq | the JSON processor (jq lessons) |
| gojq, jaq | jq reimplementations in Go and Rust: faster start, a few behaviour differences, embeddable (gojq) |
| yq (mikefarah) | jq-like YAML/JSON/TOML/XML processor that edits in place (lesson) |
| yamllint | YAML style and correctness linter (lesson) |
| check-jsonschema | validates YAML/JSON/TOML against a schema, with built-in schemas for GitHub Actions, GitLab CI, Renovate and more (lesson) |
| kubeconform | validates Kubernetes manifests against the API schemas of a given version |
| jless, fx | interactive viewers for large JSON documents |
Python
| Tool / library | What it does |
|---|---|
| uv | fast installer and project manager; uv run script.py with inline dependencies (PEP 723) |
pipx / uv tool |
installs Python CLIs into isolated environments |
| ruff | linter and formatter in one (replaces flake8, isort, black for most teams) |
| mypy, pyright | static type checkers for the type hints used in this course |
| pytest | the test framework; its tmp_path and monkeypatch fixtures fit automation code |
| click, typer | richer CLIs than argparse: command groups, prompts, completion |
| rich | tables, progress bars and coloured logs in the terminal |
| requests, httpx | HTTP clients (httpx adds async and HTTP/2) |
| tenacity | retries with backoff as a decorator |
| ruamel.yaml | YAML round-trips that keep comments (lesson) |
| boto3, google-cloud-*, azure-*, kubernetes | official SDKs, preferred over shelling out to CLIs for anything non-trivial |
Go
| Tool / library | What it does |
|---|---|
gofmt / go vet |
built-in formatting and static checks |
| golangci-lint | runs dozens of linters in one pass (staticcheck, errcheck, gosec, …) |
| Cobra + pflag | CLI framework behind kubectl, helm and gh (lesson) |
| log/slog | structured logging in the standard library (text or JSON handlers) |
errgroup (golang.org/x/sync) |
goroutines with a limit, first-error cancellation (lesson) |
| go.yaml.in/yaml/v3 | YAML for Go, the maintained continuation of the archived gopkg.in/yaml.v3 |
| GoReleaser | builds the OS/arch matrix, archives, checksums, SBOMs, container images and release notes from one file |
| govulncheck | reports known vulnerabilities that your code actually calls (Go modules course) |
One lint entry point
Whatever the tools, give the repository one command that runs all checks, and call that same command from the pre-commit hook and from CI. Here is a small one using the tools available in this course's container, run on a repository with one problem of each kind:
mkdir -p repo/scripts repo/deploy && cd repo
cat > lint.sh <<'SCRIPT'
#!/usr/bin/env bash
# lint.sh: every static check in one place; exit 1 if any failed
set -uo pipefail
status=0
step() { echo "== $1"; shift; "$@" || status=1; }
mapfile -t sh_files < <(find . -name '*.sh' -not -path './.git/*' | sort)
mapfile -t yaml_files < <(find . \( -name '*.yaml' -o -name '*.yml' \) -not -path './.git/*' | sort)
mapfile -t json_files < <(find . -name '*.json' -not -path './.git/*' | sort)
step "bash -n" bash -c 'for f; do bash -n "$f" || exit 1; done' _ "${sh_files[@]}"
step "shellcheck" shellcheck -S warning -f gcc "${sh_files[@]}"
step "yamllint" yamllint --strict -f parsable -d '{extends: default, rules: {document-start: disable}}' "${yaml_files[@]}"
step "json" bash -c 'for f; do jq empty "$f" 2>/dev/null || { echo "$f: invalid JSON"; exit 1; }; done' _ "${json_files[@]}"
[ "$status" -eq 0 ] && echo "all checks passed" || echo "some checks failed"
exit "$status"
SCRIPT
chmod +x lint.sh
printf '#!/usr/bin/env bash\nrm -rf "$BUILD_DIR"/*\ncd $1\n' > scripts/clean.sh
printf '#!/usr/bin/env bash\necho "ok"\n' > scripts/ok.sh
printf 'replicas: 2\nenabled: yes\n' > deploy/values.yaml
printf '{"name": "shop", "version": "1.4.2",}\n' > deploy/meta.json
./lint.sh; echo "-> status $?"== bash -n
== shellcheck
./scripts/clean.sh:2:8: warning: Use "${var:?}" to ensure this never expands to /* . [SC2115]
./scripts/clean.sh:3:1: warning: Use 'cd ... || exit' or 'cd ... || return' in case cd fails. [SC2164]
== yamllint
./deploy/values.yaml:2:10: [warning] truthy value should be one of [false, true] (truthy)
== json
./deploy/meta.json: invalid JSON
some checks failed
-> status 1
ShellCheck caught the classic disaster, rm -rf "$BUILD_DIR"/* with an unset variable (SC2115: it would expand
to rm -rf /*), and, since clean.sh has no set -e, the unchecked cd (SC2164). --strict makes yamllint's
truthy warning fail the step. The script keeps going after a failed step (no set -e), so one run reports every
problem, and still exits 1. In
CI the same script is one step; pre-commit can call it as a local hook:
# .pre-commit-config.yaml
repos:
- repo: local
hooks:
- id: lint
name: repository lint
entry: ./lint.sh
language: system
pass_filenames: falseTest yourself
Which tool formats shell scripts (as opposed to finding bugs in them)?
- ShellCheck
- shfmt
- bats-core
- yamllint
Why does lint.sh avoid set -e?
- set -e does not work with arrays
- So it continues after a failing check and reports every problem in one run, while still exiting 1 at the end
- ShellCheck forbids it
- It is faster
What is the benefit of one lint.sh called by both pre-commit and CI?
- CI runs faster
- Developers and CI run exactly the same checks, so 'passes locally, fails in CI' disappears
- pre-commit requires it
- It removes the need for tests