Skip to content

Commit cf4daae

Browse files
authored
Various improvements to check_line_lengths.sh (rust-lang#1667)
1 parent c869139 commit cf4daae

File tree

4 files changed

+9
-9
lines changed

4 files changed

+9
-9
lines changed

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
if: github.event_name != 'push'
4747
run: |
4848
shopt -s globstar
49-
MAX_LINE_LENGTH=100 bash ci/check_line_lengths.sh src/**/*.md
49+
MAX_LINE_LENGTH=100 bash ci/lengthcheck.sh src/**/*.md
5050
5151
- name: Install latest nightly Rust toolchain
5252
if: steps.mdbook-cache.outputs.cache-hit != 'true'

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -67,20 +67,20 @@ including the `<!-- toc -->` marker at the place where you want the TOC.
6767
### Pre-commit script
6868

6969
We also test that line lengths are less than 100 columns. To test this locally,
70-
you can run `ci/check_line_lengths.sh`.
70+
you can run `ci/lengthcheck.sh`.
7171

7272
You can also set this to run automatically.
7373

7474
On Linux:
7575

7676
```bash
77-
ln -s ../../ci/check_line_lengths.sh .git/hooks/pre-commit
77+
ln -s ../../ci/lengthcheck.sh .git/hooks/pre-commit
7878
```
7979

8080
On Windows:
8181

8282
```powershell
83-
New-Item -Path .git/hooks/pre-commit -ItemType HardLink -Value <absolute_path/to/check_line_lengths.sh>
83+
New-Item -Path .git/hooks/pre-commit -ItemType HardLink -Value $(Resolve-Path ci/lengthcheck.sh)
8484
```
8585

8686
## How to fix toolstate failures

ci/check_line_lengths.sh ci/lengthcheck.sh

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/env bash
22

3+
# Check files for lines that are too long.
4+
35
if [ "$1" == "--help" ]; then
46
echo 'Usage:' "[MAX_LINE_LENGTH=n] $0 [file ...]"
57
exit 1
@@ -10,8 +12,7 @@ if [ "$MAX_LINE_LENGTH" == "" ]; then
1012
fi
1113

1214
if [ "$1" == "" ]; then
13-
shopt -s globstar
14-
files=( src/**/*.md )
15+
files=( src/*.md src/*/*.md src/*/*/*.md )
1516
else
1617
files=( "$@" )
1718
fi
@@ -22,7 +23,6 @@ echo "Offending files and lines:"
2223
(( bad_lines = 0 ))
2324
(( inside_block = 0 ))
2425
for file in "${files[@]}"; do
25-
echo "$file"
2626
(( line_no = 0 ))
2727
while IFS="" read -r line || [[ -n "$line" ]] ; do
2828
(( line_no++ ))
@@ -34,7 +34,7 @@ for file in "${files[@]}"; do
3434
&& ! [[ "$line" =~ " | "|"-|-"|"://"|"]:"|\[\^[^\ ]+\]: ]] \
3535
&& (( "${#line}" > $MAX_LINE_LENGTH )) ; then
3636
(( bad_lines++ ))
37-
echo -e "\t$line_no : $line"
37+
echo -e "\t$file:$line_no : $line"
3838
fi
3939
done < "$file"
4040
done

src/contributing.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ There are issues for beginners and advanced compiler devs alike!
311311
Just a few things to keep in mind:
312312

313313
- Please limit line length to 100 characters. This is enforced by CI, and you can run the checks
314-
locally with `ci/check_line_lengths.sh`.
314+
locally with `ci/lengthcheck.sh`.
315315

316316
- When contributing text to the guide, please contextualize the information with some time period
317317
and/or a reason so that the reader knows how much to trust or mistrust the information.

0 commit comments

Comments
 (0)