Skip to content

Various improvements to check_line_lengths.sh #1667

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
if: github.event_name != 'push'
run: |
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
if: steps.mdbook-cache.outputs.cache-hit != 'true'
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,20 @@ including the `<!-- toc -->` marker at the place where you want the TOC.
### Pre-commit script

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.

On Linux:

```bash
ln -s ../../ci/check_line_lengths.sh .git/hooks/pre-commit
ln -s ../../ci/lengthcheck.sh .git/hooks/pre-commit
```

On Windows:

```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
Expand Down
8 changes: 4 additions & 4 deletions ci/check_line_lengths.sh → ci/lengthcheck.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env bash

# Check files for lines that are too long.

if [ "$1" == "--help" ]; then
echo 'Usage:' "[MAX_LINE_LENGTH=n] $0 [file ...]"
exit 1
Expand All @@ -10,8 +12,7 @@ if [ "$MAX_LINE_LENGTH" == "" ]; then
fi

if [ "$1" == "" ]; then
shopt -s globstar
files=( src/**/*.md )
files=( src/*.md src/*/*.md src/*/*/*.md )
else
files=( "$@" )
fi
Expand All @@ -22,7 +23,6 @@ echo "Offending files and lines:"
(( bad_lines = 0 ))
(( inside_block = 0 ))
for file in "${files[@]}"; do
echo "$file"
(( line_no = 0 ))
while IFS="" read -r line || [[ -n "$line" ]] ; do
(( line_no++ ))
Expand All @@ -34,7 +34,7 @@ for file in "${files[@]}"; do
&& ! [[ "$line" =~ " | "|"-|-"|"://"|"]:"|\[\^[^\ ]+\]: ]] \
&& (( "${#line}" > $MAX_LINE_LENGTH )) ; then
(( bad_lines++ ))
echo -e "\t$line_no : $line"
echo -e "\t$file:$line_no : $line"
fi
done < "$file"
done
Expand Down
2 changes: 1 addition & 1 deletion src/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ There are issues for beginners and advanced compiler devs alike!
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
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
and/or a reason so that the reader knows how much to trust or mistrust the information.
Expand Down