1
1
mirror of https://github.com/divnix/digga.git synced 2025-01-03 22:08:36 +03:00

💡 refactor Check exit code directly

Eliminated the redundant check for the exit code of
`editorconfig-checker`. This way is more explicit and idiomatic.

https://github.com/koalaman/shellcheck/wiki/SC2181
This commit is contained in:
Lord-Valen 2022-11-04 15:02:10 -04:00
parent f8ec6efba4
commit aa7dc0e6c3
No known key found for this signature in database
GPG Key ID: A77C43B61E4131DD

View File

@ -1,7 +1,6 @@
#!/usr/bin/env bash
if git rev-parse --verify HEAD >/dev/null 2>&1
then
if git rev-parse --verify HEAD >/dev/null 2>&1; then
against=HEAD
else
# Initial commit: diff against an empty tree object
@ -14,19 +13,17 @@ nix_files=($($diff -- '*.nix'))
all_files=($($diff))
# Format staged nix files.
if (( ${#nix_files[@]} != 0 )); then
nixpkgs-fmt "${nix_files[@]}" \
&& git add "${nix_files[@]}"
if ((${#nix_files[@]} != 0)); then
nixpkgs-fmt "${nix_files[@]}" &&
git add "${nix_files[@]}"
fi
# check editorconfig
if (( ${#all_files[@]} != 0 )); then
editorconfig-checker -- "${all_files[@]}"
fi
if [[ $? != '0' ]]; then
if ((${#all_files[@]} != 0)); then
if ! editorconfig-checker -- "${all_files[@]}"; then
printf "%b\n" \
"\nCode is not aligned with .editorconfig" \
"Review the output and commit your fixes" >&2
exit 1
fi
fi