Skip to content

Commit fb234f5

Browse files
authored
docs: update for docker-based pre-commit hooks (#266)
- Update AGENTS.md to clarify Docker-based pre-commit hooks - Update SETUP.md installation steps to use Homebrew for pre-commit - Simplify prerequisites: only Homebrew and Docker needed - Update troubleshooting section with Docker-specific guidance - Add Docker image references for each linting tool
1 parent 85761f9 commit fb234f5

2 files changed

Lines changed: 44 additions & 76 deletions

File tree

AGENTS.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,13 @@ Checks for new Node.js versions to build:
8080

8181
## Code Quality
8282

83-
- **Linting:** shellcheck (shell script linting)
84-
- **Formatting:** shfmt (enforces consistent shell style)
85-
- **Pre-commit hooks:** `.pre-commit-config.yaml` enforces checks locally before commit
86-
- shellcheck on all `.sh` and `.bats` files
87-
- shfmt on all `.sh` and `.bats` files (with `-sr -i 2 -w -ci` flags)
88-
- markdownlint-cli2 on all `.md` files (respects `.markdownlint.yaml` config)
83+
- **Linting & Formatting:** Enforced via Docker-based pre-commit hooks
84+
- **Pre-commit hooks:** `.pre-commit-config.yaml` enforces checks locally before commit using Docker
85+
- shellcheck on all `.sh` and `.bats` files (shell script linting)
86+
- shfmt on all `.sh` and `.bats` files (auto-formatting with `-sr -i 2 -w -ci` flags)
87+
- markdownlint-cli2 on all `.md` files (markdown linting with `.markdownlint.yaml` config)
8988
- See [SETUP.md](./SETUP.md) for detailed installation instructions
90-
- Quick start: `pre-commit install` then hooks run automatically on commit
89+
- Quick start: `pre-commit install` then hooks run automatically on commit (requires Docker)
9190
- **Branch Protection:** main branch requires passing checks and code owner review
9291

9392
## Testing

SETUP.md

Lines changed: 38 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ This guide explains how to set up the pre-commit hooks for this repository on ma
44

55
## Overview
66

7-
Pre-commit hooks automatically validate your code before each commit, catching issues early and ensuring consistent code quality. This repository enforces:
7+
Pre-commit hooks automatically validate your code before each commit, catching issues early and ensuring consistent code quality. This repository uses Docker-based pre-commit hooks to enforce:
88

99
- **shellcheck** - Validates shell script syntax and best practices
1010
- **shfmt** - Auto-formats shell scripts consistently
@@ -16,72 +16,39 @@ These same checks also run in GitHub Actions (checkshell.yml workflow), so using
1616

1717
Before installing pre-commit hooks, ensure you have:
1818

19-
- **Python 3.14+** - Required for the pre-commit framework
2019
- **Homebrew** - macOS package manager
21-
- **Node.js 22+ and npm** - Required for markdownlint-cli2
20+
- **Docker** - Required for running the linting tools in containers
2221

2322
## Installation Instructions
2423

2524
Follow these steps to set up pre-commit hooks on macOS:
2625

27-
### Step 1: Install Homebrew (if needed)
26+
### Step 1: Verify Docker is Installed
2827

29-
If you don't have Homebrew installed:
28+
Check that Docker is running:
3029

3130
```bash
32-
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
31+
docker --version
32+
docker ps
3333
```
3434

35-
### Step 2: Install Required Tools via Homebrew
35+
If Docker is not installed, download and install [Docker Desktop](https://www.docker.com/products/docker-desktop).
3636

37-
Install all necessary tools in one command:
37+
### Step 2: Install pre-commit Framework
3838

39-
```bash
40-
brew install pre-commit shellcheck shfmt
41-
```
42-
43-
This installs:
44-
45-
- **pre-commit 4.5.1** - Framework for managing pre-commit hooks
46-
- **shellcheck 0.11.0** - Shell script static analysis tool
47-
- **shfmt 3.12.0** - Shell script formatter (formats with `-sr -i 2 -w -ci` flags)
48-
49-
### Step 3: Install Node.js and npm (if needed)
50-
51-
If you don't have Node.js and npm, install via Homebrew:
52-
53-
```bash
54-
brew install node
55-
```
56-
57-
Alternatively, use a Node.js version manager:
39+
Install pre-commit using Homebrew:
5840

5941
```bash
60-
# Using nvm
61-
nvm install --lts
62-
63-
# Using fnm (Fast Node Manager)
64-
fnm install --lts
42+
brew install pre-commit
6543
```
6644

6745
Verify installation:
6846

6947
```bash
70-
node --version
71-
npm --version
48+
pre-commit --version
7249
```
7350

74-
### Step 4: Install markdownlint-cli2
75-
76-
Install the markdown linter globally via npm:
77-
78-
```bash
79-
npm install -g markdownlint-cli2
80-
```
81-
82-
This installs **markdownlint-cli2 v0.20.0** - Markdown file linter.
83-
84-
### Step 5: Enable Pre-commit Hooks
51+
### Step 3: Enable Pre-commit Hooks
8552

8653
Navigate to the repository and install the hooks:
8754

@@ -96,7 +63,7 @@ You should see:
9663
pre-commit installed at .git/hooks/pre-commit
9764
```
9865

99-
### Step 6: Verify Installation
66+
### Step 4: Verify Installation
10067

10168
Test that all hooks work correctly:
10269

@@ -112,13 +79,13 @@ shfmt........Passed
11279
markdownlint-cli2...Passed
11380
```
11481

115-
All three should pass without errors.
82+
All three should pass without errors. Docker will automatically pull the required container images on first run.
11683

11784
## Usage
11885

11986
### Running Hooks Automatically
12087

121-
Hooks run automatically when you commit:
88+
Hooks run automatically when you commit. Docker containers are launched automatically:
12289

12390
```bash
12491
git commit -m "Your commit message"
@@ -138,8 +105,8 @@ Run a specific hook:
138105

139106
```bash
140107
pre-commit run shellcheck --all-files
141-
pre-commit run shfmt --all-files
142-
pre-commit run markdownlint-cli2 --all-files
108+
pre-commit run shfmt-docker --all-files
109+
pre-commit run markdownlint-cli2-docker --all-files
143110
```
144111

145112
Run hooks only on changed files (default behavior at commit time):
@@ -166,13 +133,14 @@ git commit --no-verify
166133

167134
## Hook Configuration
168135

169-
Hooks are defined in `.pre-commit-config.yaml`. Here's what each hook does:
136+
Hooks are defined in `.pre-commit-config.yaml` and run inside Docker containers. Here's what each hook does:
170137

171138
### shellcheck
172139

173140
- **Purpose**: Validates shell script syntax and style
174141
- **Files checked**: `*.sh` and `*.bats`
175142
- **Configuration**: Default shellcheck rules
143+
- **Docker image**: Runs in `koalaman/shellcheck` container
176144

177145
Detects:
178146

@@ -190,6 +158,7 @@ Detects:
190158
- `-i 2`: Indent with 2 spaces
191159
- `-w`: Write changes back to files
192160
- `-ci`: Indent switch cases
161+
- **Docker image**: Runs in `mvdan/sh` container
193162

194163
Matches the formatting used in CI (GitHub Actions checkshell.yml).
195164

@@ -198,6 +167,7 @@ Matches the formatting used in CI (GitHub Actions checkshell.yml).
198167
- **Purpose**: Enforces markdown style guidelines
199168
- **Files checked**: `*.md`
200169
- **Configuration**: Respects `.markdownlint.yaml` in repository root
170+
- **Docker image**: Runs in `davidanson/markdownlint-cli2` container
201171

202172
Current settings:
203173

@@ -220,31 +190,24 @@ brew uninstall pre-commit
220190
brew install pre-commit
221191
```
222192

223-
### "shellcheck: command not found"
193+
### Docker errors when running hooks
224194

225-
**Solution**: Install via Homebrew:
226-
227-
```bash
228-
brew install shellcheck
229-
```
195+
Hooks run Docker containers for linting tools. Ensure Docker is running.
230196

231-
### "shfmt: command not found"
197+
**Solution**:
232198

233-
**Solution**: Install via Homebrew:
199+
1. Start Docker Desktop (if using macOS)
200+
2. Verify Docker is available: `docker ps`
201+
3. Check if containers can be pulled: `docker pull alpine` (test)
234202

235-
```bash
236-
brew install shfmt
237-
```
203+
### "Cannot connect to Docker daemon"
238204

239-
### "markdownlint-cli2: command not found"
205+
Docker Desktop is not running or Docker is not installed.
240206

241-
**Solution**: Install via npm:
242-
243-
```bash
244-
npm install -g markdownlint-cli2
245-
```
207+
**Solution**:
246208

247-
Make sure Node.js and npm are installed first.
209+
1. Start Docker Desktop from Applications
210+
2. Or install Docker Desktop: [https://www.docker.com/products/docker-desktop](https://www.docker.com/products/docker-desktop)
248211

249212
### Hooks not running after `pre-commit install`
250213

@@ -276,6 +239,12 @@ pre-commit clean
276239
pre-commit run --all-files
277240
```
278241

242+
### Slow first run of hooks
243+
244+
Docker container images are large. The first run will pull required images (shellcheck, shfmt, markdownlint-cli2), which may take a few minutes.
245+
246+
**Solution**: Wait for initial pull to complete. Subsequent runs will be faster as images are cached locally.
247+
279248
## CI/CD Integration
280249

281250
These same checks run in the GitHub Actions CI pipeline (`.github/workflows/checkshell.yml`):

0 commit comments

Comments
 (0)