feat: add .golangci.yml linter configuration#83
Conversation
There was a problem hiding this comment.
Pull request overview
This pull request adds golangci-lint configuration to establish automated code quality checks for the micromize project. It introduces a .golangci.yml file with linter settings, adds corresponding Makefile targets for linting and formatting, and fixes existing code issues identified by the linters.
Changes:
- New
.golangci.ymlconfiguration file with 7 enabled linters and exclusion rules - New Makefile targets:
lint,fmt,vet, andclean - Fixed 5 existing lint issues across 4 files: error handling, import ordering, file permissions, and error messages
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
.golangci.yml |
New golangci-lint v2 configuration with linters, settings, and exclusions |
Makefile |
Added lint, fmt, vet, and clean targets for code quality automation |
internal/operators/operators.go |
Added error handling for host.Init() call |
internal/runtime/manager.go |
Added error checking and logging for runtime.Close() |
cmd/micromize/root.go |
Fixed import ordering to separate stdlib, external, and local imports |
internal/utils/utils_test.go |
Changed temp file permissions from 0644 to 0600 for security |
internal/utils/utils.go |
Removed trailing message from error string per staticcheck ST1005 |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Sefi4
left a comment
There was a problem hiding this comment.
Thank you for the review! However, all four comments appear to be based on the golangci-lint v1 configuration format. This config uses version: "2" (line 1), which has a significantly different schema.
In golangci-lint v2:
linters.settingsis the correct location for linter-specific settings (not top-levellinters-settings)linters.exclusionsreplaces the oldissues.exclude-rulesfor linter exclusionsformattersis a new top-level section that separates formatting tools (gofmt,goimports) from analysis lintersgosimpleis included instaticcheck(which is already enabled) — it's not a separate linter in v2
Verification:
$ golangci-lint version
golangci-lint has version 2.10.1
$ golangci-lint config verify -v
INFO Verifying the configuration file ".golangci.yml" with the JSON Schema from https://golangci-lint.run/jsonschema/golangci.v2.10.jsonschema.json
(exit 0 — no errors)
$ golangci-lint run ./...
0 issues.
Reference: https://golangci-lint.run/docs/configuration/#version-2
f4f8128 to
e2bf6e4
Compare
e2bf6e4 to
0b7933c
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
0b7933c to
f11e34a
Compare
dorser
left a comment
There was a problem hiding this comment.
Can you change the commit message verb from "feat" to "chore"?
After that I think we can merge 👍
| with: | ||
| # This version number must be kept in sync with Makefile lint one. | ||
| version: v2.10.1 | ||
| working-directory: /home/runner/work/inspektor-gadget/inspektor-gadget |
There was a problem hiding this comment.
This is probably why the build is failing
f11e34a to
a9b03db
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
a9b03db to
35373f7
Compare
35373f7 to
9d2ae2e
Compare
9d2ae2e to
3b08a2b
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 14 out of 14 changed files in this pull request and generated 6 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| writeConfig := func(image string) { | ||
| cfg := map[string]any{"Config": map[string]string{"Image": image}} | ||
| data, _ := json.Marshal(cfg) |
There was a problem hiding this comment.
In this test helper, json.Marshal’s error is discarded (data, _ := json.Marshal(cfg)). With errcheck enabled in this PR, ignoring marshal errors is likely to be reported (and it also hides unexpected failures). Please handle the marshal error (e.g., fail the test) instead of assigning it to _.
| data, _ := json.Marshal(cfg) | |
| data, err := json.Marshal(cfg) | |
| if err != nil { | |
| t.Fatal(err) | |
| } |
| # E2E Integration Tests for PR #93 — Digest-Based BPF Map Sharing | ||
|
|
||
| Manual test scenarios for validating the functionality introduced in | ||
| [PR #93](https://github.com/micromize-dev/micromize/pull/93) which resolves | ||
| [Issue #91](https://github.com/micromize-dev/micromize/issues/91). | ||
|
|
There was a problem hiding this comment.
This new document is titled for PR #93 and references a personal branch/registry (e.g. sefitufan/..., sefiacr.azurecr.io), which doesn’t appear related to this PR’s stated goal (adding golangci-lint config + lint fixes). Consider moving this to the PR that introduced digest-based map sharing, or relocating it under docs/ with project-generic placeholders so it doesn’t bake in contributor-specific environment details.
3b08a2b to
aaeb408
Compare
- Add golangci-lint v2 configuration with linters: errcheck, errorlint, govet, ineffassign, gosec, staticcheck, unused - Add formatters: gofmt, goimports with local-prefixes - Exclude build/ directory and suppress ST1000/ST1003 staticcheck rules - Add lint, fmt, vet, clean Makefile targets - Fix errcheck: check host.Init() and runtime.Close() return values - Fix goimports: reorder imports in root.go - Fix gosec G306: use 0600 file permissions in test - Fix staticcheck ST1005: remove trailing message from error string Closes micromize-dev#45 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: Sefi Tufan <sefitufan@microsoft.com>
aaeb408 to
162fc00
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 13 out of 14 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| "github.com/go-jose/go-jose/v4/testutils/require" |
There was a problem hiding this comment.
internal/sbom/sbom_test.go adds a dependency on github.com/go-jose/go-jose/v4/testutils/require. This is a testutils package from an unrelated module and generally not intended as a stable external test assertion library; it also forces adding go-jose as a direct module dependency for a single NoError call. Prefer using standard testing checks (or an existing/common assertion library in this repo) to avoid the extra dependency and potential future breakage.
| "github.com/go-jose/go-jose/v4/testutils/require" |
There was a problem hiding this comment.
this is unrelated to this PR. I'll fix it in a follow-up PR
| require ( | ||
| github.com/cilium/ebpf v0.20.0 | ||
| github.com/cyphar/filepath-securejoin v0.5.1 | ||
| github.com/docker/cli v29.2.0+incompatible | ||
| github.com/go-jose/go-jose/v4 v4.1.3 | ||
| github.com/inspektor-gadget/inspektor-gadget v0.49.1 | ||
| github.com/opencontainers/image-spec v1.1.1 | ||
| github.com/quay/claircore v1.5.45 | ||
| github.com/sirupsen/logrus v1.9.4 | ||
| github.com/spf13/cobra v1.10.2 | ||
| golang.org/x/sync v0.19.0 |
There was a problem hiding this comment.
go.mod adds github.com/go-jose/go-jose/v4 as a direct dependency, but the only in-repo usage appears to be go-jose/v4/testutils/require in internal/sbom/sbom_test.go. Consider removing this dependency (or replacing it with standard testing assertions / a project-standard assertion lib) so the main module dependency set isn’t expanded just to support a single test helper.
Summary
Adds a
.golangci.ymlconfiguration file with sensible defaults and fixes all existing lint issues.Changes
New:
.golangci.yml(golangci-lint v2)errcheck,errorlint,govet,ineffassign,gosec,staticcheck,unusedgofmt,goimports(with local-prefixes forgithub.com/micromize-dev/micromize)build/directory,ST1000/ST1003staticcheck rules,G115gosec ruleNew Makefile targets
make lint— runsgolangci-lint run ./...make fmt— runsgofmt -w .make vet— runsgo vet ./...make clean— removes build artifactsLint fixes
internal/operators/operators.go: checkhost.Init()error returninternal/runtime/manager.go: checkruntime.Close()error returncmd/micromize/root.go: fix import ordering (goimports)internal/utils/utils_test.go: use0600file permissions (gosec G306)internal/utils/utils.go: remove trailing message from error string (staticcheck ST1005)Closes #45
Closes #46
Closes #49 (completion of the work started in #85)