From 059dc4360166fdfb6cb64bf170d45f89f763d178 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Thu, 24 Sep 2020 09:29:46 -0400 Subject: 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 --- src/doc/rustc-dev-guide/ci/check_line_lengths.sh | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'src/doc/rustc-dev-guide/ci') 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 -- cgit 1.4.1-3-g733a5