Add lint to ensure substitutions use the full form

Check that any variable substitutions use the full ${VAR} form,
not just $VAR (but don't check for quoting yet).
This commit is contained in:
Aneesh Agrawal 2016-08-04 18:12:54 -04:00
parent 79ef9b4efc
commit 9231ca1c69
10 changed files with 23 additions and 14 deletions

View file

@ -9,7 +9,7 @@ set -o nounset
set -o pipefail set -o pipefail
TARGET_DIR="${OUT_DIR}/../../.." TARGET_DIR="${OUT_DIR}/../../.."
arm-linux-androideabi-gcc "$@" \ arm-linux-androideabi-gcc "${@}" \
"${LDFLAGS-}" -lc -shared \ "${LDFLAGS-}" -lc -shared \
-o "${TARGET_DIR}/libservo.so" -o "${TARGET_DIR}/libservo.so"
touch "${TARGET_DIR}/servo" touch "${TARGET_DIR}/servo"

View file

@ -9,5 +9,5 @@ set -o nounset
set -o pipefail set -o pipefail
diff="$(git diff -- */*/Cargo.lock)" diff="$(git diff -- */*/Cargo.lock)"
echo "$diff" echo "${diff}"
[[ ! $diff ]] [[ -z "${diff}" ]]

View file

@ -17,5 +17,5 @@ set -o pipefail
./mach test-wpt --manifest-update --binary= SKIP_TESTS > /dev/null ./mach test-wpt --manifest-update --binary= SKIP_TESTS > /dev/null
diff="$(git diff -- tests/*/MANIFEST.json)" diff="$(git diff -- tests/*/MANIFEST.json)"
echo "$diff" echo "${diff}"
[[ ! $diff ]] [[ -z "${diff}" ]]

View file

@ -12,7 +12,7 @@ set -o errexit
set -o nounset set -o nounset
set -o pipefail set -o pipefail
cd "$(dirname $0)/../.." cd "$(dirname ${0})/../.."
./mach doc ./mach doc
# etc/doc.servo.org/index.html overwrites $(mach rust-root)/doc/index.html # etc/doc.servo.org/index.html overwrites $(mach rust-root)/doc/index.html

View file

@ -27,7 +27,7 @@ upload() {
main() { main() {
if [[ "$#" != 1 ]]; then if [[ "${#}" != 1 ]]; then
usage >&2 usage >&2
return 1 return 1
fi fi
@ -58,4 +58,4 @@ main() {
upload "${platform}" ${package} "${extension}" upload "${platform}" ${package} "${extension}"
} }
main "$@" main "${@}"

View file

@ -8,8 +8,8 @@ set -o errexit
set -o nounset set -o nounset
set -o pipefail set -o pipefail
if [ $# -eq 0 ]; then if [ ${#} -eq 0 ]; then
echo "Usage: $0 /path/to/gecko/objdir [other-regen.py-flags]" echo "Usage: ${0} /path/to/gecko/objdir [other-regen.py-flags]"
exit 1 exit 1
fi fi
@ -32,4 +32,4 @@ else
LIBCLANG_PATH="$(brew --prefix llvm38)/lib/llvm-3.8/lib" LIBCLANG_PATH="$(brew --prefix llvm38)/lib/llvm-3.8/lib"
fi fi
./regen.py --target all "$@" ./regen.py --target all "${@}"

View file

@ -9,7 +9,7 @@ set -o nounset
set -o pipefail set -o pipefail
# Run in the tools directory. # Run in the tools directory.
cd "$(dirname $0)" cd "$(dirname ${0})"
# Setup and build bindgen. # Setup and build bindgen.
if [ "$(uname)" == "Linux" ]; then if [ "$(uname)" == "Linux" ]; then
@ -25,8 +25,8 @@ if [ ! -x "$(command -v clang-3.8)" ]; then
exit 1 exit 1
fi fi
export LD_LIBRARY_PATH=$LIBCLANG_PATH export LD_LIBRARY_PATH="${LIBCLANG_PATH}"
export DYLD_LIBRARY_PATH=$LIBCLANG_PATH export DYLD_LIBRARY_PATH="${LIBCLANG_PATH}"
# Check for multirust # Check for multirust
if [ ! -x "$(command -v multirust)" ]; then if [ ! -x "$(command -v multirust)" ]; then

View file

@ -347,6 +347,13 @@ def check_shell(file_name, lines):
if "`" in stripped: if "`" in stripped:
yield (idx + 1, "script should not use backticks for command substitution") yield (idx + 1, "script should not use backticks for command substitution")
for dollar in re.finditer('\$', stripped):
next_idx = dollar.end()
if next_idx < len(stripped):
next_char = stripped[next_idx]
if not (next_char == '{' or next_char == '('):
yield(idx + 1, "variable substitutions should use the full \"${VAR}\" form")
def check_rust(file_name, lines): def check_rust(file_name, lines):
if not file_name.endswith(".rs") or \ if not file_name.endswith(".rs") or \

View file

@ -7,3 +7,4 @@ set -o nounset
# Talking about some `concept in backticks` # shouldn't trigger # Talking about some `concept in backticks` # shouldn't trigger
echo "hello world" echo "hello world"
some_var=`echo "command substitution"` some_var=`echo "command substitution"`
another_var="$some_var"

View file

@ -53,6 +53,7 @@ class CheckTidiness(unittest.TestCase):
self.assertEqual('script does not have shebang "#!/usr/bin/env bash"', errors.next()[2]) self.assertEqual('script does not have shebang "#!/usr/bin/env bash"', errors.next()[2])
self.assertEqual('script is missing options "set -o errexit", "set -o pipefail"', errors.next()[2]) self.assertEqual('script is missing options "set -o errexit", "set -o pipefail"', errors.next()[2])
self.assertEqual('script should not use backticks for command substitution', errors.next()[2]) self.assertEqual('script should not use backticks for command substitution', errors.next()[2])
self.assertEqual('variable substitutions should use the full \"${VAR}\" form', errors.next()[2])
self.assertNoMoreErrors(errors) self.assertNoMoreErrors(errors)
def test_rust(self): def test_rust(self):