Skip to content

Commit

Permalink
feat(bash): Add bash format checks
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenj committed Nov 28, 2023
1 parent dcfffea commit cadc405
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
14 changes: 14 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[*.sh]
# like -i=4
indent_style = space
indent_size = 4

# --language-variant
shell_variant = bash
binary_next_line = true
# --case-indent
switch_case_indent = true
space_redirects = true
keep_padding = false
# --func-next-line
function_next_line = false
3 changes: 2 additions & 1 deletion earthly/bash/Earthfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ builder:

RUN apk add --no-cache \
bash \
shellcheck
shellcheck \
shfmt

WORKDIR /work
COPY check-all.sh shellcheck-dir.sh duplicated-scripts.sh .
Expand Down
19 changes: 16 additions & 3 deletions earthly/bash/check-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@
# Run `shellcheck` on all files in a directory, recursively.
# $1 = The directory to check.

basedir=$(dirname "$0")
if [[ ${BASH_SOURCE[0]} = */* ]]; then
basedir=${BASH_SOURCE%/*}
else
basedir=.
fi

# Get our includes relative to this file's location.
source "${basedir}/include/colors.sh"

echo BASEDIR = "${basedir}"

rc=0

"${basedir}"/duplicated-scripts.sh "$1"
Expand All @@ -16,12 +19,22 @@ rc_dup=$?
"${basedir}"/shellcheck-dir.sh "$1"
rc_lint=$?

FORCECOLOR=1 shfmt -d .
rc_shfmt=$?

# Return an error if any of this fails.
status "${rc}" "Duplicated Bash Scripts" \
[ "${rc_dup}" == 0 ]
rc=$?
status "${rc}" "Lint Errors in Bash Scripts" \
[ "${rc_lint}" == 0 ]
rc=$?
status "${rc}" "ShellFmt Errors in Bash Scripts" \
[ "${rc_shfmt}" == 0 ]
rc=$?

if [[ ${rc_shfmt} -ne 0 ]]; then
echo "Shell files can be autoformated with: 'shfmt -w .' from the root of the repo."
fi

exit "${rc}"

0 comments on commit cadc405

Please sign in to comment.