diff options
| author | Joshua Nelson <jyn514@gmail.com> | 2020-09-24 09:29:46 -0400 |
|---|---|---|
| committer | Joshua Nelson <joshua@yottadb.com> | 2020-10-01 01:27:11 -0400 |
| commit | 059dc4360166fdfb6cb64bf170d45f89f763d178 (patch) | |
| tree | 76a6d87963902b0e960c5f751ee2aaebdb66959f /src/doc/rustc-dev-guide | |
| parent | 2bb145daa4e067a7bb19b87e7eae8f48f1938aed (diff) | |
| download | rust-059dc4360166fdfb6cb64bf170d45f89f763d178.tar.gz rust-059dc4360166fdfb6cb64bf170d45f89f763d178.zip | |
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
Diffstat (limited to 'src/doc/rustc-dev-guide')
| -rw-r--r-- | src/doc/rustc-dev-guide/README.md | 11 | ||||
| -rwxr-xr-x | src/doc/rustc-dev-guide/ci/check_line_lengths.sh | 17 |
2 files changed, 19 insertions, 9 deletions
diff --git a/src/doc/rustc-dev-guide/README.md b/src/doc/rustc-dev-guide/README.md index 5dbd5d27f35..fd83cea2d5b 100644 --- a/src/doc/rustc-dev-guide/README.md +++ b/src/doc/rustc-dev-guide/README.md @@ -76,6 +76,17 @@ and execute the following command in the root of the repository: The build files are found in the `book` directory. +### 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 also set this to run automatically with the following command: + +```bash +ln -s ../../ci/check_line_lengths.sh .git/hooks/pre-commit +``` + ### Link Validations 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: diff --git a/src/doc/rustc-dev-guide/ci/check_line_lengths.sh b/src/doc/rustc-dev-guide/ci/check_line_lengths.sh index 32bf739e4dc..8ecb8a309b6 100755 --- a/src/doc/rustc-dev-guide/ci/check_line_lengths.sh +++ b/src/doc/rustc-dev-guide/ci/check_line_lengths.sh @@ -1,19 +1,18 @@ -#!/bin/bash +#!/usr/bin/env bash if [ "$1" == "--help" ]; then - echo 'Usage:' - echo ' MAX_LINE_LENGTH=100' "$0" 'src/**/*.md' - exit 1 + echo 'Usage:' "[MAX_LINE_LENGTH=n] $0 [file ...]" + exit 1 fi if [ "$MAX_LINE_LENGTH" == "" ]; then - echo '`MAX_LINE_LENGTH` environment variable not set. Try --help.' - exit 1 + MAX_LINE_LENGTH=100 fi if [ "$1" == "" ]; then - echo 'No files provided.' - exit 1 + files=( src/**/*.md ) +else + files=( "$@" ) fi echo "Checking line lengths in all source files <= $MAX_LINE_LENGTH chars..." @@ -21,7 +20,7 @@ echo "Checking line lengths in all source files <= $MAX_LINE_LENGTH chars..." echo "Offending files and lines:" (( bad_lines = 0 )) (( inside_block = 0 )) -for file in "$@" ; do +for file in "${files[@]}"; do echo "$file" (( line_no = 0 )) while IFS="" read -r line || [[ -n "$line" ]] ; do |
