Skip to content

Commit d51e0d6

Browse files
committed
feat: pass module dir as --path-prefix arg to golangci-lint
This ensures that the path output reported by golangci-lint is qualified with respect to a given linted file's path within the repo. Without this option, just the filename itself is outputted, leading to ambiguity as to which file is problematic when multiple files have the same name (e.g. `main.go`).
1 parent 6451653 commit d51e0d6

File tree

4 files changed

+8
-0
lines changed

4 files changed

+8
-0
lines changed

golangci-lint-mod.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
#!/usr/bin/env bash
22
cmd=(golangci-lint run)
3+
cmd_pwd_arg="--path-prefix"
34
. "$(dirname "${0}")/lib/cmd-mod.bash"

golangci-lint-repo-mod.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
#!/usr/bin/env bash
22
cmd=(golangci-lint run)
3+
cmd_pwd_arg="--path-prefix"
34
. "$(dirname "${0}")/lib/cmd-repo-mod.bash"

lib/cmd-mod.bash

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ error_code=0
1414
#
1515
for sub in $(find_module_roots "${FILES[@]}" | sort -u); do
1616
pushd "${sub}" > /dev/null || exit 1
17+
if [ "${cmd_pwd_arg:-}" ]; then
18+
OPTIONS+=("${cmd_pwd_arg}=${sub}")
19+
fi
1720
if [ "${error_on_output:-}" -eq 1 ]; then
1821
output=$(/usr/bin/env "${ENV_VARS[@]}" "${cmd[@]}" "${OPTIONS[@]}" 2>&1)
1922
if [ -n "${output}" ]; then

lib/cmd-repo-mod.bash

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ error_code=0
1414
#
1515
for sub in $(find . -name go.mod -not -path '*/vendor/*' -exec dirname "{}" ';' | sort -u); do
1616
pushd "${sub}" > /dev/null || exit 1
17+
if [ "${cmd_pwd_arg:-}" ]; then
18+
OPTIONS+=("${cmd_pwd_arg}=${sub}")
19+
fi
1720
if [ "${error_on_output:-}" -eq 1 ]; then
1821
output=$(/usr/bin/env "${ENV_VARS[@]}" "${cmd[@]}" "${OPTIONS[@]}" 2>&1)
1922
if [ -n "${output}" ]; then

0 commit comments

Comments
 (0)