Files
mongo/buildscripts/shellscripts-linters.sh
Zack Winter 0b642e6c7d SERVER-98913 Run shell script linters as part of "bazel run format" (#30743)
GitOrigin-RevId: 35f56889b14e79c5669f2386f817400d6b93f65e
2025-01-02 18:43:22 +00:00

42 lines
807 B
Bash
Executable File

#!/bin/bash
set +o errexit
if [ -n "$BUILD_WORKSPACE_DIRECTORY" ]; then
cd $BUILD_WORKSPACE_DIRECTORY
fi
if ! command -v shfmt &>/dev/null; then
echo "Could not find the 'shfmt' command"
echo ""
echo "Install via"
echo ""
echo " brew install shfmt"
echo ""
exit 1
fi
lint_dirs="evergreen"
if [ "$1" = "fix" ]; then
shfmt -w -i 2 -bn -sr "$lint_dirs"
fi
output_file="shfmt_output.txt"
exit_code=0
shfmt -d -i 2 -bn -sr "$lint_dirs" >"$output_file"
if [ -s "$output_file" ]; then
echo "ERROR: Found formatting errors in shell script files in directories: $lint_dirs"
echo ""
cat "$output_file"
echo ""
echo "To fix formatting errors run"
echo ""
echo " ./buildscripts/shellscripts-linters.sh fix"
echo ""
exit_code=1
fi
rm -rf "$output_file"
exit "$exit_code"