mirror of
https://github.com/kiddin9/op-packages.git
synced 2026-10-27 05:32:51 +08:00
🎉 Sync 2026-09-27 21:03:26
This commit is contained in:
1 parent
f4559bbed1
commit
065763f7fd
673 files changed
+261285
-34160
No files matched your search
Executable
+73
@@ -0,0 +1,73 @@
|
||||
#!/bin/sh
|
||||
# shellcheck shell=sh
|
||||
set -eu
|
||||
|
||||
ROOT="$(CDPATH='' cd -- "$(dirname -- "$0")/.." && pwd)"
|
||||
TMPFILE="$(mktemp)"
|
||||
|
||||
cleanup() {
|
||||
rm -f "$TMPFILE"
|
||||
}
|
||||
trap cleanup EXIT HUP INT TERM
|
||||
|
||||
cd "$ROOT"
|
||||
|
||||
command -v shfmt >/dev/null 2>&1 || {
|
||||
echo "error: shfmt is required" >&2
|
||||
exit 127
|
||||
}
|
||||
|
||||
command -v shellcheck >/dev/null 2>&1 || {
|
||||
echo "error: shellcheck is required" >&2
|
||||
exit 127
|
||||
}
|
||||
|
||||
collect_file() {
|
||||
file="$1"
|
||||
[ -f "$file" ] || return 0
|
||||
|
||||
case "$file" in
|
||||
spec/*_spec.sh)
|
||||
# ShellSpec DSL is valid shell syntax but is not supported by shfmt.
|
||||
return 0
|
||||
;;
|
||||
*.sh | */init.d/* | */uci-defaults/* | */hotplug.d/*)
|
||||
printf '%s\n' "$file" >>"$TMPFILE"
|
||||
return 0
|
||||
;;
|
||||
esac
|
||||
|
||||
if head -n 1 "$file" 2>/dev/null | grep -Eq '^#!.*(sh|ash|bash)([[:space:]]|$)'; then
|
||||
printf '%s\n' "$file" >>"$TMPFILE"
|
||||
fi
|
||||
}
|
||||
|
||||
if git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
|
||||
git ls-files | while IFS= read -r file; do
|
||||
collect_file "$file"
|
||||
done
|
||||
else
|
||||
find . -type f -print | sed 's#^\./##' | while IFS= read -r file; do
|
||||
collect_file "$file"
|
||||
done
|
||||
fi
|
||||
|
||||
sort -u "$TMPFILE" -o "$TMPFILE"
|
||||
|
||||
if [ ! -s "$TMPFILE" ]; then
|
||||
echo "No shell files found."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
echo "Checking shell formatting with shfmt..."
|
||||
xargs -r shfmt -d -ci <"$TMPFILE"
|
||||
|
||||
echo "Checking shell scripts with ShellCheck..."
|
||||
xargs -r shellcheck -x -S warning <"$TMPFILE"
|
||||
|
||||
echo "Checking shell syntax..."
|
||||
while IFS= read -r file; do
|
||||
sh -n "$file"
|
||||
done <"$TMPFILE"
|
||||
|
||||
echo "Shell lint passed."
|
||||
Reference in new issue
Block a user