Only match #!/bin/bash in scripts
Our dib-lint checking is only considering scripts with #!/bin/bash. While there's nothing really wrong with some other shebang line like "#!/usr/bin/env bash" let's keep things consistent. We can use the same regex match to reduce a few forks in the main checking. Also a minor cleanup to the file matching Change-Id: I609721b2671e704ea26075dad7e5b39a8b858f6b
This commit is contained in:
parent
c31a59a2c9
commit
d8abe72537
14
bin/dib-lint
14
bin/dib-lint
@ -63,12 +63,15 @@ TMPDIR=$(mktemp -d /tmp/tmp.XXXXXXXXXX)
|
|||||||
trap "rm -rf $TMPDIR" EXIT
|
trap "rm -rf $TMPDIR" EXIT
|
||||||
for i in $(find elements -type f \
|
for i in $(find elements -type f \
|
||||||
-not -name \*~ \
|
-not -name \*~ \
|
||||||
|
-not -name \#\*\# \
|
||||||
-not -name \*.orig \
|
-not -name \*.orig \
|
||||||
-not -name \*.rst \
|
-not -name \*.rst \
|
||||||
-not -name \*.yaml \
|
-not -name \*.yaml \
|
||||||
-not -name \*.py \
|
-not -name \*.py \
|
||||||
-not -name \*.pyc); do
|
-not -name \*.pyc); do
|
||||||
|
|
||||||
exclusions=("$(parse_exclusions $i)")
|
exclusions=("$(parse_exclusions $i)")
|
||||||
|
|
||||||
# Check that files starting with a shebang are +x
|
# Check that files starting with a shebang are +x
|
||||||
firstline=$(head -n 1 "$i")
|
firstline=$(head -n 1 "$i")
|
||||||
if [ "${firstline:0:2}" = "#!" ]; then
|
if [ "${firstline:0:2}" = "#!" ]; then
|
||||||
@ -77,7 +80,6 @@ for i in $(find elements -type f \
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Ensure 4 spaces indent are used
|
# Ensure 4 spaces indent are used
|
||||||
|
|
||||||
if [ "$(file -b --mime-type $i)" = "text/x-python" ]; then
|
if [ "$(file -b --mime-type $i)" = "text/x-python" ]; then
|
||||||
flake8 $i
|
flake8 $i
|
||||||
else
|
else
|
||||||
@ -104,6 +106,14 @@ for i in $(find elements -type f \
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# for consistency, let's just use #!/bin/bash everywhere (not
|
||||||
|
# /usr/bin/env, etc)
|
||||||
|
regex='^#!.*bash'
|
||||||
|
if [[ "$firstline" =~ $regex &&
|
||||||
|
"$firstline" != "#!/bin/bash" ]]; then
|
||||||
|
error "$i : only use #!/bin/bash for scripts"
|
||||||
|
fi
|
||||||
|
|
||||||
# Check that all scripts are set -eu -o pipefail and look for
|
# Check that all scripts are set -eu -o pipefail and look for
|
||||||
# DIB_DEBUG_TRACE
|
# DIB_DEBUG_TRACE
|
||||||
# NOTE(bnemec): This doesn't verify that the set call occurs high
|
# NOTE(bnemec): This doesn't verify that the set call occurs high
|
||||||
@ -114,7 +124,7 @@ for i in $(find elements -type f \
|
|||||||
# explicitly require bash for any scripts that don't have a specific
|
# explicitly require bash for any scripts that don't have a specific
|
||||||
# need to run under other shells, and any exceptions to that rule
|
# need to run under other shells, and any exceptions to that rule
|
||||||
# may not want these checks either.
|
# may not want these checks either.
|
||||||
if [ -n "$(echo $firstline | grep '#!/bin/bash')" ]; then
|
if [[ "$firstline" =~ '#!/bin/bash' ]]; then
|
||||||
if ! excluded sete; then
|
if ! excluded sete; then
|
||||||
if [ -z "$(grep "^set -[^ ]*e" $i)" ]; then
|
if [ -z "$(grep "^set -[^ ]*e" $i)" ]; then
|
||||||
error "$i is not set -e"
|
error "$i is not set -e"
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
#!/usr/bin/env bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Copyright 2016 Matthew Thode
|
# Copyright 2016 Matthew Thode
|
||||||
#
|
#
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#!/usr/bin/env bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Copyright 2016 Matthew Thode
|
# Copyright 2016 Matthew Thode
|
||||||
# All Rights Reserved.
|
# All Rights Reserved.
|
||||||
#
|
#
|
||||||
|
Loading…
Reference in New Issue
Block a user