Skip to content

Commit 905eb94

Browse files
committed
Use --hook:path-prefix arg to make golangci-lint --path-prefix optional
1 parent d51e0d6 commit 905eb94

File tree

4 files changed

+15
-2
lines changed

4 files changed

+15
-2
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ You can copy/paste the following snippet into your `.pre-commit-config.yaml` fil
112112
# - Can be configured to replace MOST other hooks
113113
# - Supports repo config file for configuration
114114
# - https://github.com/golangci/golangci-lint
115+
# - Use arg `--hook:path-prefix` to indicate that the repository root
116+
# directory be passed to the tool as prefix (for `*-mod` hooks)
115117
#
116118
- id: golangci-lint
117119
- id: golangci-lint-mod

golangci-lint-mod.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#!/usr/bin/env bash
22
cmd=(golangci-lint run)
3-
cmd_pwd_arg="--path-prefix"
3+
if [ "${path_prefix:-}" -eq 1 ]; then
4+
cmd_pwd_arg="--path-prefix"
5+
fi
46
. "$(dirname "${0}")/lib/cmd-mod.bash"

golangci-lint-repo-mod.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#!/usr/bin/env bash
22
cmd=(golangci-lint run)
3-
cmd_pwd_arg="--path-prefix"
3+
if [ "${path_prefix:-}" -eq 1 ]; then
4+
cmd_pwd_arg="--path-prefix"
5+
fi
46
. "$(dirname "${0}")/lib/cmd-repo-mod.bash"

lib/prepare-my-cmd.bash

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ while [ $# -gt 0 ] && [ "$1" != "--" ]; do
2222
#
2323
shift
2424
;;
25+
--hook:path-prefix)
26+
path_prefix=1
27+
# We continue (vs break) in order to consume multiple occurrences
28+
# of the arg. VERY unlikely but let's be safe.
29+
#
30+
shift
31+
;;
2532
*) # preserve positional arguments
2633
__ARGS+=("$1")
2734
shift

0 commit comments

Comments
 (0)