|
639 | 639 | }; |
640 | 640 | }; |
641 | 641 | }; |
| 642 | + golangci-lint = mkOption { |
| 643 | + description = "golangci-lint hook"; |
| 644 | + type = types.submodule { |
| 645 | + imports = [ hookModule ]; |
| 646 | + options = { |
| 647 | + settings = { |
| 648 | + configPath = mkOption { |
| 649 | + type = types.nullOr types.str; |
| 650 | + description = "Path to the config file."; |
| 651 | + default = null; |
| 652 | + }; |
| 653 | + flags = mkOption { |
| 654 | + type = types.str; |
| 655 | + description = "Flags passed to golangci-lint."; |
| 656 | + default = ""; |
| 657 | + example = "--new-from-rev HEAD --fix"; |
| 658 | + }; |
| 659 | + }; |
| 660 | + packageOverrides = { |
| 661 | + go = mkOption { |
| 662 | + type = types.package; |
| 663 | + description = "The go package to use."; |
| 664 | + }; |
| 665 | + }; |
| 666 | + }; |
| 667 | + }; |
| 668 | + }; |
642 | 669 | golines = mkOption { |
643 | 670 | description = "golines hook"; |
644 | 671 | type = types.submodule { |
@@ -2972,25 +2999,39 @@ lib.escapeShellArgs (lib.concatMap (ext: [ "--ghc-opt" "-X${ext}" ]) hooks.fourm |
2972 | 2999 | builtins.toString script; |
2973 | 3000 | files = "\\.go$"; |
2974 | 3001 | }; |
2975 | | - golangci-lint = { |
2976 | | - name = "golangci-lint"; |
2977 | | - description = "Fast linters runner for Go."; |
2978 | | - package = tools.golangci-lint; |
2979 | | - entry = |
2980 | | - let |
2981 | | - script = pkgs.writeShellScript "precommit-golangci-lint" '' |
2982 | | - set -e |
2983 | | - for dir in $(echo "$@" | xargs -n1 dirname | sort -u); do |
2984 | | - ${hooks.golangci-lint.package}/bin/golangci-lint run ./"$dir" |
2985 | | - done |
2986 | | - ''; |
2987 | | - in |
2988 | | - builtins.toString script; |
2989 | | - files = "\\.go$"; |
2990 | | - # to avoid multiple invocations of the same directory input, provide |
2991 | | - # all file names in a single run. |
2992 | | - require_serial = true; |
2993 | | - }; |
| 3002 | + golangci-lint = |
| 3003 | + let |
| 3004 | + inherit (hooks.golangci-lint) packageOverrides; |
| 3005 | + wrapper = pkgs.runCommand "golangci-lint-wrapped" |
| 3006 | + { |
| 3007 | + buildInputs = [ pkgs.makeWrapper ]; |
| 3008 | + } '' |
| 3009 | + makeWrapper ${tools.golangci-lint}/bin/golangci-lint $out/bin/golangci-lint \ |
| 3010 | + --prefix PATH : ${packageOverrides.go}/bin |
| 3011 | + ''; |
| 3012 | + in |
| 3013 | + { |
| 3014 | + name = "golangci-lint"; |
| 3015 | + description = "Fast linters runner for Go."; |
| 3016 | + package = wrapper; |
| 3017 | + packageOverrides = { inherit (tools) go; }; |
| 3018 | + entry = |
| 3019 | + let |
| 3020 | + inherit (hooks.golangci-lint) settings; |
| 3021 | + configArg = lib.optionalString (settings.configPath != null) "--config ${settings.configPath}"; |
| 3022 | + script = pkgs.writeShellScript "precommit-golangci-lint" '' |
| 3023 | + set -e |
| 3024 | + for dir in $(echo "$@" | xargs -n1 dirname | sort -u); do |
| 3025 | + ${hooks.golangci-lint.package}/bin/golangci-lint run ${configArg} ${settings.flags} ./"$dir" |
| 3026 | + done |
| 3027 | + ''; |
| 3028 | + in |
| 3029 | + builtins.toString script; |
| 3030 | + files = "\\.go$"; |
| 3031 | + # to avoid multiple invocations of the same directory input, provide |
| 3032 | + # all file names in a single run. |
| 3033 | + require_serial = true; |
| 3034 | + }; |
2994 | 3035 | golines = |
2995 | 3036 | { |
2996 | 3037 | name = "golines"; |
|
0 commit comments