github.com/jaegerpicker/docker@v0.7.7-0.20150325003727-22dba32b4dab/hack/make/validate-spaces (about)

     1  #!/bin/bash
     2  
     3  source "$(dirname "$BASH_SOURCE")/.validate"
     4  
     5  #Ignoring files from vendor/, builder/parser/testfiles*, docs/theme/mkdocs/tipuesearch*, ending with .md and .go
     6  ignoreFiles='^builder/parser/testfiles*|^docs/theme/mkdocs/tipuesearch*|^vendor/|\.md$|\.go$'
     7  
     8  IFS=$'\n'
     9  files=( $(validate_diff --diff-filter=ACMR --name-only | grep -v "$ignoreFiles" || true) )
    10  unset IFS
    11  
    12  badFiles=()
    13  for f in "${files[@]}"; do
    14      if [ "$(git show "$VALIDATE_HEAD:$f" | grep '[[:space:]]$')" ]; then
    15          badFiles+=( "$f" )
    16      fi
    17  done
    18  
    19  if [ ${#badFiles[@]} -eq 0 ]; then
    20  	echo 'Congratulations!  All text files are properly formatted.'
    21  else
    22  	{
    23  		echo "These files have trailing whitespaces:"
    24  		for f in "${badFiles[@]}"; do
    25  			echo " - $f"
    26  		done
    27  		echo
    28  		echo 'Please reformat the above files using, for example:'
    29  		echo '"ex -sc "'"%s/[[:space:]]*$//g|x"'" file" and commit the result.'
    30  		echo
    31  	} >&2
    32  	false
    33  fi