chore: improve project checks
This commit is contained in:
@@ -1,12 +1,16 @@
|
|||||||
.PHONY: all check lint test format
|
.PHONY: all check format format-check lint test
|
||||||
|
|
||||||
check: format lint test
|
all: format check
|
||||||
|
check: format-check lint test
|
||||||
test:
|
|
||||||
@scripts/test
|
|
||||||
|
|
||||||
lint:
|
|
||||||
@scripts/lint
|
|
||||||
|
|
||||||
format:
|
format:
|
||||||
@stylua .
|
@stylua $(or $(FILES),.)
|
||||||
|
|
||||||
|
format-check:
|
||||||
|
@stylua --check $(or $(FILES),.)
|
||||||
|
|
||||||
|
lint:
|
||||||
|
@scripts/lint $(FILES)
|
||||||
|
|
||||||
|
test:
|
||||||
|
@scripts/test $(FILES)
|
||||||
|
|||||||
+44
-4
@@ -3,15 +3,55 @@ set -uo pipefail
|
|||||||
|
|
||||||
cd "$(dirname "$0")/.." || exit 1
|
cd "$(dirname "$0")/.." || exit 1
|
||||||
|
|
||||||
emmylua_check --warnings-as-errors --output-format=json . 2> >(grep -v '^Check finished$' >&2) \
|
filter='.'
|
||||||
| jq -r '
|
if [[ $# -gt 0 ]]; then
|
||||||
|
files_json=$(printf '%s\n' "$@" | jq -R -s 'split("\n")[:-1]')
|
||||||
|
read -r -d "" filter <<'jq'
|
||||||
|
def selected($path; $rel):
|
||||||
|
any($files[]; . as $target
|
||||||
|
| ($target | sub("/+$"; "") | sub("^\\./"; "")) as $clean
|
||||||
|
| (if $clean | startswith("/") then $clean else $cwd + "/" + $clean end) as $abs
|
||||||
|
| $path == $clean
|
||||||
|
or $rel == $clean
|
||||||
|
or $path == $abs
|
||||||
|
or ($rel | startswith($clean + "/"))
|
||||||
|
or ($path | startswith($abs + "/"))
|
||||||
|
);
|
||||||
|
map(
|
||||||
|
.file as $f
|
||||||
|
| ($f | sub("^" + $cwd + "/"; "")) as $rel
|
||||||
|
| select(selected($f; $rel))
|
||||||
|
)
|
||||||
|
jq
|
||||||
|
fi
|
||||||
|
|
||||||
|
json=$(emmylua_check --warnings-as-errors --output-format=json . 2> >(grep -v '^Check finished$' >&2))
|
||||||
|
check_status=$?
|
||||||
|
if ! jq -e type >/dev/null <<<"$json"; then
|
||||||
|
if [[ $check_status -ne 0 ]]; then
|
||||||
|
exit "$check_status"
|
||||||
|
fi
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
if ! filtered=$(jq --arg cwd "$PWD" --argjson files "${files_json:-[]}" "$filter" <<<"$json"); then
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
jq -r '
|
||||||
.[]
|
.[]
|
||||||
| .file as $f
|
| .file as $f
|
||||||
| .diagnostics[]
|
| .diagnostics[]
|
||||||
| "\($f):\(.range.start.line + 1):\(.range.start.character + 1)"
|
| "\($f):\(.range.start.line + 1):\(.range.start.character + 1)"
|
||||||
+ ": \(["error","warning","info","hint"][.severity-1])"
|
+ ": \(["error","warning","info","hint"][.severity-1])"
|
||||||
+ ": \(.message | rtrimstr(" ")) [\(.code)]"
|
+ ": \(.message | rtrimstr(" ")) [\(.code)]"
|
||||||
' \
|
' <<<"$filtered" \
|
||||||
| sed "s|^$PWD/||"
|
| sed "s|^$PWD/||"
|
||||||
|
|
||||||
exit "${PIPESTATUS[0]}"
|
if [[ $# -gt 0 ]]; then
|
||||||
|
if jq -e 'any(.[]?.diagnostics[]?; .severity <= 2)' >/dev/null <<<"$filtered"; then
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
exit "$check_status"
|
||||||
|
|||||||
Reference in New Issue
Block a user