/ maint / rust-maint-common / forbid-script-extensions
forbid-script-extensions
 1  #!/usr/bin/env bash
 2  #
 3  # Forbid scripts containing a dot in their filename.
 4  # The aim is to forbid encoding the implementation language.
 5  #
 6  # This is a very common antipattern.  Almost, dominant.  But it's bad.
 7  # It means call sites (including maybe out-of-tree) and human habits
 8  # must change if the script is rewritten in a different language.
 9  #
10  # This rule only applies to *executable* files, which can be invoked
11  # by their name.  Script modules or fragments which are to be included
12  # are fine, since their language is part of their API.
13  
14  set -euo pipefail
15  
16  # this include stanza is automatically maintained by update-shell-includes
17  common_dir=$(realpath "$0")
18  common_dir=$(dirname "$common_dir")
19  # shellcheck source=maint/common/bash-utils.sh
20  . "$common_dir"/bash-utils.sh
21  
22  reject_all_arguments
23  
24  wrong=$(
25      # shellcheck disable=SC2086
26      find -H . -xdev \( -name .git -prune \) -o \( \
27  	 -type f -name '*.*' \! -name '*~' -perm /111 \
28  	 -ls \
29      \)
30  )
31  
32  if [ "$wrong" = "" ]; then exit 0; fi
33  
34  printf '%s\n' "$wrong"
35  
36  fail 'dot is forbidden in script filenames
37  (scripts should not encode their implementation language in their filename)'