Skip to content

[TASK] ci: enforce gofmt in the lint pipeline #287

Description

@Aravinda-HWK

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

  1. Introduce a gofmt violation (for example, remove leading tabs from several lines inside a function).
  2. Push the change or open a PR.
  3. Observe that the lint job passes even though:
gofmt -l .

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

  • A PR containing a gofmt violation fails the lint pipeline.
  • gofmt -l . returns no output on main.
  • The chosen approach is documented in the contributing guide or PR checklist (optional).

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Fields

    No fields configured for Task.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions