Skip to content

Commit 4a6fd11

Browse files
jyn514Joshua Nelson
authored and
Joshua Nelson
committed
Recommend setting up check_line_lengths as a pre-commit script
I've run into lots of annoying failures from this. - Make it runnable without arguments - Add it in the README
1 parent a8b7e92 commit 4a6fd11

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

README.md

+11
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,17 @@ and execute the following command in the root of the repository:
7676

7777
The build files are found in the `book` directory.
7878

79+
### Pre-commit script
80+
81+
We also test that line lengths are less than 100 columns. To test this locally,
82+
you can run `ci/check_line_lengths.sh`.
83+
84+
You can also set this to run automatically with the following command:
85+
86+
```bash
87+
ln -s ../../ci/check_line_lengths.sh .git/hooks/pre-commit
88+
```
89+
7990
### Link Validations
8091

8192
We use `mdbook-linkcheck` to validate URLs included in our documentation. To perform link checks, uncomment the `[output.linkcheck]` field in the `book.toml` configuration file and install `mdbook-linkcheck` with:

ci/check_line_lengths.sh

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,26 @@
1-
#!/bin/bash
1+
#!/usr/bin/env bash
22

33
if [ "$1" == "--help" ]; then
4-
echo 'Usage:'
5-
echo ' MAX_LINE_LENGTH=100' "$0" 'src/**/*.md'
6-
exit 1
4+
echo 'Usage:' "[MAX_LINE_LENGTH=n] $0 [file ...]"
5+
exit 1
76
fi
87

98
if [ "$MAX_LINE_LENGTH" == "" ]; then
10-
echo '`MAX_LINE_LENGTH` environment variable not set. Try --help.'
11-
exit 1
9+
MAX_LINE_LENGTH=100
1210
fi
1311

1412
if [ "$1" == "" ]; then
15-
echo 'No files provided.'
16-
exit 1
13+
files=( src/**/*.md )
14+
else
15+
files=( "$@" )
1716
fi
1817

1918
echo "Checking line lengths in all source files <= $MAX_LINE_LENGTH chars..."
2019

2120
echo "Offending files and lines:"
2221
(( bad_lines = 0 ))
2322
(( inside_block = 0 ))
24-
for file in "$@" ; do
23+
for file in "${files[@]}"; do
2524
echo "$file"
2625
(( line_no = 0 ))
2726
while IFS="" read -r line || [[ -n "$line" ]] ; do

0 commit comments

Comments
 (0)