Skip to content
This repository was archived by the owner on Jul 2, 2026. It is now read-only.

Commit ca75da9

Browse files
committed
fix(godoc-lint): fix golangci-lint version-detection regex
The v1.1.5 v2-compat patch used `sed -n 's/.*version v\([0-9]\+\).*/\1/p'`, which (a) requires the `v` prefix that current `golangci-lint version` output no longer emits (`golangci-lint has version 2.12.2 built with ...`) and (b) uses `\{0,1\}` quantifier in BRE that BSD sed on macOS doesn't accept. Switched to `sed -E -n 's/.*version v?([0-9]+).*/\1/p'` (ERE; `v` optional). Without this, every consumer with golangci-lint v2.x falls through to the `--disable-all` branch and trips "unknown flag" again. Surfaced on html-to-markdown's prek run after the v1.1.5 bump.
1 parent 54c3454 commit ca75da9

2 files changed

Lines changed: 14 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Fixed
1111

12+
- `godoc-lint`: fix `golangci-lint` version-detection regex. The v1.1.5
13+
v2-compat patch used `sed -n 's/.*version v\([0-9]\+\).*/\1/p'`, which
14+
(a) requires the `v` prefix that current `golangci-lint version` output
15+
no longer emits (`golangci-lint has version 2.12.2 built with ...`) and
16+
(b) uses `\{0,1\}` quantifier in BRE that BSD sed on macOS doesn't accept.
17+
Switched to `sed -E -n 's/.*version v?([0-9]+).*/\1/p'` (ERE; `v` optional).
18+
Without this, every consumer with golangci-lint v2.x falls through to the
19+
`--disable-all` branch and trips "unknown flag" again. Surfaced on
20+
html-to-markdown's prek run after the v1.1.5 bump. (`hooks/godoc-lint/run.sh`)
21+
1222
- `godoc-lint`: support `golangci-lint` v2.x. v2 removed the `--disable-all`
1323
flag in favour of `--default=none`, so v1.1.4 and earlier failed with
1424
"unknown flag: --disable-all" against v2 installations. The hook now

hooks/godoc-lint/run.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@ if command -v golangci-lint >/dev/null 2>&1; then
3434
# v2 removed `--disable-all` and replaced it with `--default=none`. Detect
3535
# the major version once and pick the matching flag set so this hook works
3636
# against both v1.x and v2.x consumers.
37-
glc_major="$(golangci-lint version 2>&1 | sed -n 's/.*version v\([0-9]\+\).*/\1/p' | head -n 1)"
37+
# `golangci-lint version` prints e.g. "golangci-lint has version 2.12.2 built with ..."
38+
# (no `v` prefix). Match the first integer immediately after the literal "version ".
39+
# Use `sed -E` (extended regex) — BSD sed on macOS doesn't support `\{0,1\}` quantifier in BRE.
40+
glc_major="$(golangci-lint version 2>&1 | sed -E -n 's/.*version v?([0-9]+).*/\1/p' | head -n 1)"
3841
if [[ "${glc_major}" =~ ^[0-9]+$ ]] && ((glc_major >= 2)); then
3942
only_revive_args=(--default=none --enable=revive)
4043
else

0 commit comments

Comments
 (0)