summaryrefslogtreecommitdiff
path: root/maint/rust-maint-common/forbid-hard-tabs
blob: fbd66d417455d515b5e22e747481070f4e3ae756 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env bash
#
# Usage:
#   maint/forbid-hard-tabs [GIT-FILE-SPECIFICATIONS ...]
#
# Requires that source code files contain no hard tabs.
#
# GIT-FILE-SPECIFICATIONS are arguments to git grep.
#
# (GIT-FILE-SPECIFICATIONS are passed to `git grep` after `--`,
# so we run `git grep ... -- GIT-FILE-SPECIFICATIONS`.
# That ensures the file specifications are interpreted by git as `<pathspec>`s.)
#
# If not specified, the default is
#     :*.c :*.py :*.rs :*.toml :*.yaml :*.yml

set -euo pipefail

# this include stanza is automatically maintained by update-shell-includes
common_dir=$(realpath "$0")
common_dir=$(dirname "$common_dir")
# shellcheck source=maint/common/bash-utils.sh
. "$common_dir"/bash-utils.sh

reject_options

if [ $# = 0 ]; then
    set :\*.{c,py,rs,toml,yaml,yml}
fi

set +e
git --no-pager grep '	' -- "$@"
st=$?
set -e

case "$st" in
    0)
	echo "Hard tabs found.  Please use spaces for indentation."
	exit 1
	;;
    1)
	echo "Everything seems ok"
	exit 0
	;;
    *)
	echo "ERROR - status $st"
	exit 16
	;;
esac