mirror of
https://github.com/servo/servo.git
synced 2025-07-23 15:23:42 +01:00
Add lint for [
instead of [[
in shells scripts
This commit is contained in:
parent
9231ca1c69
commit
f07d8f188a
5 changed files with 17 additions and 8 deletions
|
@ -8,25 +8,25 @@ 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
|
||||||
|
|
||||||
# Check for rust-bindgen
|
# Check for rust-bindgen
|
||||||
if [ ! -d rust-bindgen ]; then
|
if [[ ! -d rust-bindgen ]]; then
|
||||||
echo "rust-bindgen not found. Run setup_bindgen.sh first."
|
echo "rust-bindgen not found. Run setup_bindgen.sh first."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Check for /usr/include
|
# Check for /usr/include
|
||||||
if [ ! -d /usr/include ]; then
|
if [[ ! -d /usr/include ]]; then
|
||||||
echo "/usr/include doesn't exist." \
|
echo "/usr/include doesn't exist." \
|
||||||
"Mac users may need to run xcode-select --install."
|
"Mac users may need to run xcode-select --install."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "$(uname)" == "Linux" ]; then
|
if [[ "$(uname)" == "Linux" ]]; then
|
||||||
LIBCLANG_PATH=/usr/lib/llvm-3.8/lib
|
LIBCLANG_PATH=/usr/lib/llvm-3.8/lib
|
||||||
else
|
else
|
||||||
LIBCLANG_PATH="$(brew --prefix llvm38)/lib/llvm-3.8/lib"
|
LIBCLANG_PATH="$(brew --prefix llvm38)/lib/llvm-3.8/lib"
|
||||||
|
|
|
@ -12,14 +12,14 @@ set -o pipefail
|
||||||
cd "$(dirname ${0})"
|
cd "$(dirname ${0})"
|
||||||
|
|
||||||
# Setup and build bindgen.
|
# Setup and build bindgen.
|
||||||
if [ "$(uname)" == "Linux" ]; then
|
if [[ "$(uname)" == "Linux" ]]; then
|
||||||
export LIBCLANG_PATH=/usr/lib/llvm-3.8/lib
|
export LIBCLANG_PATH=/usr/lib/llvm-3.8/lib
|
||||||
else
|
else
|
||||||
export LIBCLANG_PATH="$(brew --prefix llvm38)/lib/llvm-3.8/lib"
|
export LIBCLANG_PATH="$(brew --prefix llvm38)/lib/llvm-3.8/lib"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Make sure we have llvm38.
|
# Make sure we have llvm38.
|
||||||
if [ ! -x "$(command -v clang-3.8)" ]; then
|
if [[ ! -x "$(command -v clang-3.8)" ]]; then
|
||||||
echo "llmv38 must be installed." \
|
echo "llmv38 must be installed." \
|
||||||
"Mac users should |brew install llvm38|, Linux varies by distro."
|
"Mac users should |brew install llvm38|, Linux varies by distro."
|
||||||
exit 1
|
exit 1
|
||||||
|
@ -29,13 +29,13 @@ 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
|
||||||
echo "multirust must be installed."
|
echo "multirust must be installed."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Don't try to clone twice.
|
# Don't try to clone twice.
|
||||||
if [ ! -d rust-bindgen ]; then
|
if [[ ! -d rust-bindgen ]]; then
|
||||||
git clone https://github.com/servo/rust-bindgen.git
|
git clone https://github.com/servo/rust-bindgen.git
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
|
@ -347,6 +347,9 @@ 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")
|
||||||
|
|
||||||
|
if " [ " in stripped or stripped.startswith("[ "):
|
||||||
|
yield (idx + 1, "script should use `[[` instead of `[` for conditional testing")
|
||||||
|
|
||||||
for dollar in re.finditer('\$', stripped):
|
for dollar in re.finditer('\$', stripped):
|
||||||
next_idx = dollar.end()
|
next_idx = dollar.end()
|
||||||
if next_idx < len(stripped):
|
if next_idx < len(stripped):
|
||||||
|
|
|
@ -8,3 +8,7 @@ set -o nounset
|
||||||
echo "hello world"
|
echo "hello world"
|
||||||
some_var=`echo "command substitution"`
|
some_var=`echo "command substitution"`
|
||||||
another_var="$some_var"
|
another_var="$some_var"
|
||||||
|
if [ -z "${some_var}" ]; then
|
||||||
|
echo "should have used [["
|
||||||
|
fi
|
||||||
|
[ -z "${another_var}" ]
|
||||||
|
|
|
@ -54,6 +54,8 @@ class CheckTidiness(unittest.TestCase):
|
||||||
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.assertEqual('variable substitutions should use the full \"${VAR}\" form', errors.next()[2])
|
||||||
|
self.assertEqual('script should use `[[` instead of `[` for conditional testing', errors.next()[2])
|
||||||
|
self.assertEqual('script should use `[[` instead of `[` for conditional testing', errors.next()[2])
|
||||||
self.assertNoMoreErrors(errors)
|
self.assertNoMoreErrors(errors)
|
||||||
|
|
||||||
def test_rust(self):
|
def test_rust(self):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue