Various improvements to `check_line_lengths.sh` (#1667)

This commit is contained in:
jyn 2023-04-08 22:08:46 -05:00 committed by GitHub
parent c869139156
commit cf4daae9a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 9 additions and 9 deletions

View File

@ -46,7 +46,7 @@ jobs:
if: github.event_name != 'push' if: github.event_name != 'push'
run: | run: |
shopt -s globstar shopt -s globstar
MAX_LINE_LENGTH=100 bash ci/check_line_lengths.sh src/**/*.md MAX_LINE_LENGTH=100 bash ci/lengthcheck.sh src/**/*.md
- name: Install latest nightly Rust toolchain - name: Install latest nightly Rust toolchain
if: steps.mdbook-cache.outputs.cache-hit != 'true' if: steps.mdbook-cache.outputs.cache-hit != 'true'

View File

@ -67,20 +67,20 @@ including the `<!-- toc -->` marker at the place where you want the TOC.
### Pre-commit script ### Pre-commit script
We also test that line lengths are less than 100 columns. To test this locally, We also test that line lengths are less than 100 columns. To test this locally,
you can run `ci/check_line_lengths.sh`. you can run `ci/lengthcheck.sh`.
You can also set this to run automatically. You can also set this to run automatically.
On Linux: On Linux:
```bash ```bash
ln -s ../../ci/check_line_lengths.sh .git/hooks/pre-commit ln -s ../../ci/lengthcheck.sh .git/hooks/pre-commit
``` ```
On Windows: On Windows:
```powershell ```powershell
New-Item -Path .git/hooks/pre-commit -ItemType HardLink -Value <absolute_path/to/check_line_lengths.sh> New-Item -Path .git/hooks/pre-commit -ItemType HardLink -Value $(Resolve-Path ci/lengthcheck.sh)
``` ```
## How to fix toolstate failures ## How to fix toolstate failures

View File

@ -1,5 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Check files for lines that are too long.
if [ "$1" == "--help" ]; then if [ "$1" == "--help" ]; then
echo 'Usage:' "[MAX_LINE_LENGTH=n] $0 [file ...]" echo 'Usage:' "[MAX_LINE_LENGTH=n] $0 [file ...]"
exit 1 exit 1
@ -10,8 +12,7 @@ if [ "$MAX_LINE_LENGTH" == "" ]; then
fi fi
if [ "$1" == "" ]; then if [ "$1" == "" ]; then
shopt -s globstar files=( src/*.md src/*/*.md src/*/*/*.md )
files=( src/**/*.md )
else else
files=( "$@" ) files=( "$@" )
fi fi
@ -22,7 +23,6 @@ echo "Offending files and lines:"
(( bad_lines = 0 )) (( bad_lines = 0 ))
(( inside_block = 0 )) (( inside_block = 0 ))
for file in "${files[@]}"; do for file in "${files[@]}"; do
echo "$file"
(( line_no = 0 )) (( line_no = 0 ))
while IFS="" read -r line || [[ -n "$line" ]] ; do while IFS="" read -r line || [[ -n "$line" ]] ; do
(( line_no++ )) (( line_no++ ))
@ -34,7 +34,7 @@ for file in "${files[@]}"; do
&& ! [[ "$line" =~ " | "|"-|-"|"://"|"]:"|\[\^[^\ ]+\]: ]] \ && ! [[ "$line" =~ " | "|"-|-"|"://"|"]:"|\[\^[^\ ]+\]: ]] \
&& (( "${#line}" > $MAX_LINE_LENGTH )) ; then && (( "${#line}" > $MAX_LINE_LENGTH )) ; then
(( bad_lines++ )) (( bad_lines++ ))
echo -e "\t$line_no : $line" echo -e "\t$file:$line_no : $line"
fi fi
done < "$file" done < "$file"
done done

View File

@ -311,7 +311,7 @@ There are issues for beginners and advanced compiler devs alike!
Just a few things to keep in mind: Just a few things to keep in mind:
- Please limit line length to 100 characters. This is enforced by CI, and you can run the checks - Please limit line length to 100 characters. This is enforced by CI, and you can run the checks
locally with `ci/check_line_lengths.sh`. locally with `ci/lengthcheck.sh`.
- When contributing text to the guide, please contextualize the information with some time period - When contributing text to the guide, please contextualize the information with some time period
and/or a reason so that the reader knows how much to trust or mistrust the information. and/or a reason so that the reader knows how much to trust or mistrust the information.