/ maint / rust-maint-common / forbid-hard-tabs
forbid-hard-tabs
 1  #!/usr/bin/env bash
 2  #
 3  # Usage:
 4  #   maint/forbid-hard-tabs [GIT-FILE-SPECIFICATIONS ...]
 5  #
 6  # Requires that source code files contain no hard tabs.
 7  #
 8  # GIT-FILE-SPECIFICATIONS are arguments to git grep.
 9  #
10  # (GIT-FILE-SPECIFICATIONS are passed to `git grep` after `--`,
11  # so we run `git grep ... -- GIT-FILE-SPECIFICATIONS`.
12  # That ensures the file specifications are interpreted by git as `<pathspec>`s.)
13  #
14  # If not specified, the default is
15  #     :*.c :*.py :*.rs :*.toml :*.yaml :*.yml
16  
17  set -euo pipefail
18  
19  # this include stanza is automatically maintained by update-shell-includes
20  common_dir=$(realpath "$0")
21  common_dir=$(dirname "$common_dir")
22  # shellcheck source=maint/common/bash-utils.sh
23  . "$common_dir"/bash-utils.sh
24  
25  reject_options
26  
27  if [ $# = 0 ]; then
28      set :\*.{c,py,rs,toml,yaml,yml}
29  fi
30  
31  set +e
32  git --no-pager grep '	' -- "$@"
33  st=$?
34  set -e
35  
36  case "$st" in
37      0)
38  	echo "Hard tabs found.  Please use spaces for indentation."
39  	exit 1
40  	;;
41      1)
42  	echo "Everything seems ok"
43  	exit 0
44  	;;
45      *)
46  	echo "ERROR - status $st"
47  	exit 16
48  	;;
49  esac