Skip to content

Commit

Permalink
Add tidying and linting for shell code and clean some shell up
Browse files Browse the repository at this point in the history
  • Loading branch information
autarch committed Dec 1, 2024
1 parent 0fe1bfc commit 20a7069
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 16 deletions.
10 changes: 5 additions & 5 deletions do-release.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

cargo release --package precious-helpers $@
cargo release --package precious-testhelper $@
cargo release --package precious-core $@
cargo release --package precious-integration $@
cargo release --package precious $@
cargo release --package precious-helpers "$@"
cargo release --package precious-testhelper "$@"
cargo release --package precious-core "$@"
cargo release --package precious-integration "$@"
cargo release --package precious "$@"
18 changes: 9 additions & 9 deletions examples/golang/helpers/check-go-mod.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,33 @@

set -e

ROOT=$( git rev-parse --show-toplevel )
BEFORE_MOD=$( md5sum "$ROOT/go.mod" )
BEFORE_SUM=$( md5sum "$ROOT/go.sum" )
ROOT=$(git rev-parse --show-toplevel)
BEFORE_MOD=$(md5sum "$ROOT/go.mod")
BEFORE_SUM=$(md5sum "$ROOT/go.sum")

OUTPUT=$( go mod tidy -v 2>&1 )
OUTPUT=$(go mod tidy -v 2>&1)

AFTER_MOD=$( md5sum "$ROOT/go.mod" )
AFTER_SUM=$( md5sum "$ROOT/go.sum" )
AFTER_MOD=$(md5sum "$ROOT/go.mod")
AFTER_SUM=$(md5sum "$ROOT/go.sum")

red=$'\e[1;31m'
end=$'\e[0m'

if [ "$BEFORE_MOD" != "$AFTER_MOD" ]; then
printf "${red}Running go mod tidy changed the contents of go.mod${end}\n"
printf "%sRunning go mod tidy changed the contents of go.mod%s\n" "$red" "$end"
git diff "$ROOT/go.mod"
changed=1
fi

if [ "$BEFORE_SUM" != "$AFTER_SUM" ]; then
printf "${red}Running go mod tidy changed the contents of go.sum${end}\n"
printf "%sRunning go mod tidy changed the contents of go.sum%s\n" "$red" "$end"
git diff "$ROOT/go.sum"
changed=1
fi

if [ -n "$changed" ]; then
if [ -n "$OUTPUT" ]; then
printf "\nOutput from running go mod tidy -v:\n${OUTPUT}\n"
printf "\nOutput from running go mod tidy -v:\n%s\n" "$OUTPUT"
else
printf "\nThere was no output from running go mod tidy -v\n\n"
fi
Expand Down
4 changes: 2 additions & 2 deletions git/hooks/pre-commit.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
#!/bin/bash

declare -i status
status=0

PRECIOUS=$(which precious)
if [[ -z $PRECIOUS ]]; then
PRECIOUS=./bin/precious
fi

"$PRECIOUS" lint -s
if (( $? != 0 )); then
if ! "$PRECIOUS" lint -s; then
status+=1
fi

Expand Down
17 changes: 17 additions & 0 deletions precious.toml
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,23 @@ ok-exit-codes = 0
lint-failure-exit-codes = 1
ignore-stderr = ["The .+ file is not sorted", "The .+ file is not unique"]

[commands.shellcheck]
type = "lint"
include = "**/*.sh"
cmd = "shellcheck"
ok_exit_codes = 0
lint_failure_exit_codes = 1

[commands.shfmt]
type = "both"
include = "**/*.sh"
cmd = ["shfmt", "--simplify", "--indent", "4"]
lint_flags = "--diff"
tidy_flags = "--write"
ok_exit_codes = 0
lint_failure_exit_codes = 1
labels = ["default", "fast-tidy"]

[commands.typos]
type = "lint"
include = "**/*"
Expand Down

0 comments on commit 20a7069

Please sign in to comment.