flake: add --check option to formatter

Add an option to check the formatting without modifying files.
This will be can be used in CI checks.
This commit is contained in:
beviu authored and Felix Uhl committed 2024-09-26 12:52:03 +02:00
1 parent 1879e48907
commit 4c4c869c2d
1 file changed
+52 -4
+52 -4
View File
@@ -85,10 +85,58 @@
deadnix deadnix
]; ];
text = '' text = ''
set -o xtrace showUsage() {
nixpkgs-fmt "$@" cat <<EOF
deno fmt "$@" Usage: $0 [OPTIONS] FILES...
deadnix --edit "$@" -c, --check Only check formatting, do not modify files.
-h, --help Show this help message.
EOF
}
check=
files=()
parseArgs() {
while [[ $# -gt 0 ]]; do
case "$1" in
-h | --help)
showUsage
exit 0
;;
-c | --check)
check=1
;;
*)
files+=("$1")
;;
esac
shift
done
if [[ ''${#files[@]} -eq 0 ]]; then
files=(.)
fi
}
main() {
parseArgs "$@"
if [[ -z "$check" ]]; then
set -o xtrace
nixpkgs-fmt -- "''${files[@]}"
deno fmt -- "''${files[@]}"
deadnix --edit -- "''${files[@]}"
else
set -o xtrace
nixpkgs-fmt --check -- "''${files[@]}"
deno fmt --check -- "''${files[@]}"
deadnix -- "''${files[@]}"
fi
}
main "$@"
''; '';
} }
); );