Skip to content

Commit 2fd176f

Browse files
retlehsclaude
andauthored
Add CI lint for single-command bash blocks (#563)
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent e7c7f5b commit 2fd176f

4 files changed

Lines changed: 82 additions & 5 deletions

File tree

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Lint bash code blocks
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- '**/*.md'
7+
8+
jobs:
9+
check-bash-blocks:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v4
13+
14+
- name: Check for multi-line bash code blocks
15+
run: |
16+
fail=0
17+
while IFS= read -r file; do
18+
# Strip leading ./ so GitHub annotations link to the correct file
19+
clean="${file#./}"
20+
awk -v file="$clean" '
21+
/^```bash/ { in_block=1; lines=0; start=NR; next }
22+
/^```/ && in_block {
23+
if (lines > 1) {
24+
printf "::error file=%s,line=%d::Bash code block has multiple commands. Each block must contain exactly one command.\n", file, start
25+
found=1
26+
}
27+
in_block=0; next
28+
}
29+
in_block && /^[^#]/ && !/^[[:space:]]*$/ { lines++ }
30+
END { if (found) exit 1 }
31+
' "$file" || fail=1
32+
done < <(find . -name '*.md' -not -path './.git/*' -not -name 'CLAUDE.md')
33+
34+
if [ "$fail" -eq 1 ]; then
35+
echo ""
36+
echo "Error: Found bash code blocks with multiple commands."
37+
echo "Each bash code block must contain exactly one command."
38+
exit 1
39+
fi
40+
41+
echo "All bash code blocks contain a single command."

CLAUDE.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Docs Conventions
2+
3+
## Markdown bash code blocks
4+
5+
Each bash code block must contain exactly one command. Never combine multiple commands in a single block. On the roots.io front-end, bash code blocks have a clipboard copy button that only supports single lines.
6+
7+
Good:
8+
9+
````markdown
10+
```bash
11+
composer require example/package
12+
```
13+
14+
```bash
15+
wp plugin activate example
16+
```
17+
````
18+
19+
Bad:
20+
21+
````markdown
22+
```bash
23+
composer require example/package
24+
wp plugin activate example
25+
```
26+
````

bedrock/converting-wordpress-sites-to-bedrock.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ Create a new Bedrock installation:
2828

2929
```bash
3030
$ composer create-project roots/bedrock example.com
31+
```
32+
33+
```bash
3134
$ cd example.com
3235
```
3336

@@ -65,6 +68,9 @@ Activate Lithify and run the conversion command:
6568

6669
```bash
6770
$ wp plugin activate lithify
71+
```
72+
73+
```bash
6874
$ wp lithify
6975
```
7076

trellis/redis.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -309,13 +309,17 @@ This setup uses three different cache systems:
309309
Monitor Redis usage:
310310

311311
```bash
312-
# Redis CLI
313312
redis-cli
313+
```
314314

315-
# Inside Redis CLI
316-
INFO memory
317-
INFO stats
315+
```bash
316+
redis-cli INFO memory
317+
```
318318

319-
# Monitor real-time commands
319+
```bash
320+
redis-cli INFO stats
321+
```
322+
323+
```bash
320324
redis-cli MONITOR
321325
```

0 commit comments

Comments
 (0)