What needs to be done?
Description
Our CI lint job (.github/workflows/linters.yaml) runs golangci-lint but does not fail on gofmt violations. In golangci-lint v2, formatters such as gofmt and gofumpt are opt-in, and there is currently no .golangci.yml configuration in the repository enabling them. As a result, unformatted Go code can pass CI.
This was observed in PR #286, where extractAllHeaders in internal/delivery/parser/parser.go was committed with non-gofmt indentation and the lint job still passed.
Expected Behavior
CI should fail whenever any committed .go file is not formatted with gofmt.
Steps to Reproduce
- Introduce a
gofmt violation (for example, remove leading tabs from several lines inside a function).
- Push the change or open a PR.
- Observe that the lint job passes even though:
reports the affected file.
Proposed Solution
Option A — Dedicated gofmt Check (Recommended)
Add an explicit formatting check step to the golangci job in linters.yaml:
- name: gofmt check
run: |
unformatted=$(gofmt -l .)
if [ -n "$unformatted" ]; then
echo "::error::The following files are not gofmt-formatted:"
echo "$unformatted"
exit 1
fi
Advantages:
- Simple and explicit.
- Independent of
golangci-lint configuration changes.
- Easy to understand and maintain.
Option B — Enable gofmt in golangci-lint v2
Add a .golangci.yml file at the repository root:
version: "2"
formatters:
enable:
- gofmt
Ensure CI runs golangci-lint with --fix=false so formatting issues are reported rather than automatically fixed.
Advantages:
- Keeps all linting and formatting checks centralized in a single tool.
Acceptance Criteria
Notes
Option A is recommended for clarity and to avoid relying on golangci-lint formatter configuration semantics. Option B is also valid if the project prefers keeping all code quality checks within golangci-lint.
What needs to be done?
Description
Our CI lint job (
.github/workflows/linters.yaml) runsgolangci-lintbut does not fail ongofmtviolations. Ingolangci-lintv2, formatters such asgofmtandgofumptare opt-in, and there is currently no.golangci.ymlconfiguration in the repository enabling them. As a result, unformatted Go code can pass CI.This was observed in PR #286, where
extractAllHeadersininternal/delivery/parser/parser.gowas committed with non-gofmtindentation and the lint job still passed.Expected Behavior
CI should fail whenever any committed
.gofile is not formatted withgofmt.Steps to Reproduce
gofmtviolation (for example, remove leading tabs from several lines inside a function).gofmt -l .reports the affected file.
Proposed Solution
Option A — Dedicated
gofmtCheck (Recommended)Add an explicit formatting check step to the
golangcijob inlinters.yaml:Advantages:
golangci-lintconfiguration changes.Option B — Enable
gofmtingolangci-lintv2Add a
.golangci.ymlfile at the repository root:Ensure CI runs
golangci-lintwith--fix=falseso formatting issues are reported rather than automatically fixed.Advantages:
Acceptance Criteria
gofmtviolation fails the lint pipeline.gofmt -l .returns no output onmain.Notes
Option A is recommended for clarity and to avoid relying on
golangci-lintformatter configuration semantics. Option B is also valid if the project prefers keeping all code quality checks withingolangci-lint.