diff options
author | Artur Manuel <[email protected]> | 2024-10-07 19:49:19 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2024-10-07 21:49:19 +0300 |
commit | 46d990f1b632dc52a667d876a32cffb24ef72bd8 (patch) | |
tree | a73acf2f403d09715b7e51cc07edfb9f359cab65 /nix/formatter.nix | |
parent | 5bf7b1e1fadf743f41ec765f7545370e3d7ccf96 (diff) | |
download | Hyprland-46d990f1b632dc52a667d876a32cffb24ef72bd8.tar.gz Hyprland-46d990f1b632dc52a667d876a32cffb24ef72bd8.zip |
feat: add a custom made treewide formatter (#7992)
Diffstat (limited to 'nix/formatter.nix')
-rw-r--r-- | nix/formatter.nix | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/nix/formatter.nix b/nix/formatter.nix new file mode 100644 index 00000000..66721c2c --- /dev/null +++ b/nix/formatter.nix @@ -0,0 +1,64 @@ +{ + writeShellApplication, + deadnix, + statix, + alejandra, + llvmPackages_19, + fd, +}: +writeShellApplication { + name = "hyprland-treewide-formatter"; + runtimeInputs = [ + deadnix + statix + alejandra + llvmPackages_19.clang-tools + fd + ]; + text = '' + # shellcheck disable=SC2148 + + # common excludes + excludes="subprojects" + + nix_format() { + if [ "$*" = 0 ]; then + fd '.*\.nix' . -E "$excludes" -x statix fix -- {} \; + fd '.*\.nix' . -E "$excludes" -X deadnix -e -- {} \; -X alejandra {} \; + elif [ -d "$1" ]; then + fd '.*\.nix' "$1" -E "$excludes" -i -x statix fix -- {} \; + fd '.*\.nix' "$1" -E "$excludes" -i -X deadnix -e -- {} \; -X alejandra {} \; + else + statix fix -- "$1" + deadnix -e "$1" + alejandra "$1" + fi + } + + cpp_format() { + if [ "$*" = 0 ] || [ "$1" = "." ]; then + fd '.*\.cpp' . -E "$excludes" | xargs clang-format --verbose -i + elif [ -d "$1" ]; then + fd '.*\.cpp' "$1" -E "$excludes" | xargs clang-format --verbose -i + else + clang-format --verbose -i "$1" + fi + } + + for i in "$@"; do + case ''${i##*.} in + "nix") + nix_format "$i" + ;; + "cpp") + cpp_format "$i" + ;; + *) + nix_format "$i" + cpp_format "$i" + ;; + esac + + done + ''; +} |