Skip to content

Commit 2e2de42

Browse files
authored
ci: add gofmt check (#199)
Adds a formatting check to CI that fails when any Go file is not `gofmt`-clean. Nothing in CI catches unformatted Go today: `.github/workflows/lint.yml` installs `golangci-lint` but never runs it. This change adds a `fmt` job to the same workflow that runs `make fmt` and uses the existing `scripts/check_unstaged.sh` to fail on any diff. `types/diagnostics_test.go` was already not `gofmt`-clean on `main`; that reformat is included. Generated with Coder Agents.
1 parent 5e77ead commit 2e2de42

3 files changed

Lines changed: 20 additions & 3 deletions

File tree

.github/workflows/lint.yml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,17 @@ jobs:
3535
${{ env.LINT_CACHE_DIR }}
3636
key: golangci-lint-${{ runner.os }}-${{ hashFiles('**/*.go') }}
3737
restore-keys: |
38-
golangci-lint-${{ runner.os }}-
38+
golangci-lint-${{ runner.os }}-
39+
40+
fmt:
41+
runs-on: ubuntu-latest
42+
timeout-minutes: 5
43+
steps:
44+
- uses: actions/checkout@v5.0.0
45+
- uses: actions/setup-go@v5
46+
with:
47+
go-version: 1.22.8
48+
- name: make fmt
49+
run: make fmt
50+
- name: Check for unstaged files
51+
run: ./scripts/check_unstaged.sh

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,8 @@ gen:
55

66
.PHONY: clean-testdata
77
clean-testdata:
8-
git clean -xfd testdata
8+
git clean -xfd testdata
9+
10+
.PHONY: fmt
11+
fmt:
12+
gofmt -w .

types/diagnostics_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func TestDiagnosticExtra(t *testing.T) {
4040
// The `parent` wrapped is lost here, so calling `SetDiagnosticExtra` is
4141
// lossy. In practice, we only call this once, so it's ok.
4242
// TODO: Fix SetDiagnosticExtra to maintain the parents
43-
// if the DiagnosticExtra already exists in the chain.
43+
// if the DiagnosticExtra already exists in the chain.
4444
func TestDiagnosticExtraExisting(t *testing.T) {
4545
diag := &hcl.Diagnostic{
4646
Severity: hcl.DiagWarning,

0 commit comments

Comments
 (0)