blob: 0330099c62b043d6365999b42e77c01c97867225 (
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
|
#!/usr/bin/env bash
#
# Forbid scripts containing a dot in their filename.
# The aim is to forbid encoding the implementation language.
#
# This is a very common antipattern. Almost, dominant. But it's bad.
# It means call sites (including maybe out-of-tree) and human habits
# must change if the script is rewritten in a different language.
#
# This rule only applies to *executable* files, which can be invoked
# by their name. Script modules or fragments which are to be included
# are fine, since their language is part of their API.
set -euo pipefail
fail () {
echo >&2 "error; $*"
exit 8
}
if [ "$#" != 0 ]; then
fail "no arguments allowed"
fi
wrong=$(
# shellcheck disable=SC2086
find -H . -xdev \( -name .git -prune \) -o \( \
-type f -name '*.*' \! -name '*~' -perm /111 \
-ls \
\)
)
if [ "$wrong" = "" ]; then exit 0; fi
printf '%s\n' "$wrong"
fail 'dot is forbidden in script filenames
(scripts should not encode their implementation language in their filename)'
|