Skip to content

feat: add .golangci.yml linter configuration#83

Merged
dorser merged 1 commit into
micromize-dev:mainfrom
Sefi4:sefitufan/add-golangci-lint-config
Mar 1, 2026
Merged

feat: add .golangci.yml linter configuration#83
dorser merged 1 commit into
micromize-dev:mainfrom
Sefi4:sefitufan/add-golangci-lint-config

Conversation

@Sefi4

@Sefi4 Sefi4 commented Feb 25, 2026

Copy link
Copy Markdown

Summary

Adds a .golangci.yml configuration file with sensible defaults and fixes all existing lint issues.

Changes

New: .golangci.yml (golangci-lint v2)

  • Linters: errcheck, errorlint, govet, ineffassign, gosec, staticcheck, unused
  • Formatters: gofmt, goimports (with local-prefixes for github.com/micromize-dev/micromize)
  • Exclusions: build/ directory, ST1000/ST1003 staticcheck rules, G115 gosec rule
  • Timeout: 5 minutes

New Makefile targets

  • make lint — runs golangci-lint run ./...
  • make fmt — runs gofmt -w .
  • make vet — runs go vet ./...
  • make clean — removes build artifacts

Lint fixes

  • internal/operators/operators.go: check host.Init() error return
  • internal/runtime/manager.go: check runtime.Close() error return
  • cmd/micromize/root.go: fix import ordering (goimports)
  • internal/utils/utils_test.go: use 0600 file 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)

Copilot AI review requested due to automatic review settings February 25, 2026 20:35

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.yml configuration file with 7 enabled linters and exclusion rules
  • New Makefile targets: lint, fmt, vet, and clean
  • 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.

Comment thread .golangci.yml
Comment thread .golangci.yml
Comment thread .golangci.yml
Comment thread .golangci.yml

@Sefi4 Sefi4 left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.settings is the correct location for linter-specific settings (not top-level linters-settings)
  • linters.exclusions replaces the old issues.exclude-rules for linter exclusions
  • formatters is a new top-level section that separates formatting tools (gofmt, goimports) from analysis linters
  • gosimple is included in staticcheck (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

@Sefi4 Sefi4 force-pushed the sefitufan/add-golangci-lint-config branch from f4f8128 to e2bf6e4 Compare February 25, 2026 21:23
Comment thread Makefile Outdated
Comment thread Makefile Outdated
Copilot AI review requested due to automatic review settings February 27, 2026 09:42
@Sefi4 Sefi4 force-pushed the sefitufan/add-golangci-lint-config branch from e2bf6e4 to 0b7933c Compare February 27, 2026 09:42

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread Makefile
Comment thread Dockerfiles/linter.Dockerfile Outdated
@Sefi4 Sefi4 force-pushed the sefitufan/add-golangci-lint-config branch from 0b7933c to f11e34a Compare February 27, 2026 09:54

@dorser dorser left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change the commit message verb from "feat" to "chore"?
After that I think we can merge 👍

Comment thread .github/workflows/build.yml Outdated
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

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is probably why the build is failing

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops

@Sefi4 Sefi4 force-pushed the sefitufan/add-golangci-lint-config branch from f11e34a to a9b03db Compare February 27, 2026 16:43
Copilot AI review requested due to automatic review settings February 27, 2026 16:43

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread .golangci.yml Outdated
Comment thread Makefile
Comment thread Makefile
Comment thread internal/utils/utils.go Outdated
@Sefi4 Sefi4 force-pushed the sefitufan/add-golangci-lint-config branch from a9b03db to 35373f7 Compare February 27, 2026 17:54
Copilot AI review requested due to automatic review settings February 28, 2026 09:07
@Sefi4 Sefi4 force-pushed the sefitufan/add-golangci-lint-config branch from 35373f7 to 9d2ae2e Compare February 28, 2026 09:07
@Sefi4 Sefi4 force-pushed the sefitufan/add-golangci-lint-config branch from 9d2ae2e to 3b08a2b Compare February 28, 2026 09:08
@Sefi4 Sefi4 requested a review from dorser February 28, 2026 09:09

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread Dockerfiles/linter.Dockerfile
Comment thread internal/sbom/sbom.go
Comment thread internal/sbom/sbom_test.go Outdated

writeConfig := func(image string) {
cfg := map[string]any{"Config": map[string]string{"Image": image}}
data, _ := json.Marshal(cfg)

Copilot AI Feb 28, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 _.

Suggested change
data, _ := json.Marshal(cfg)
data, err := json.Marshal(cfg)
if err != nil {
t.Fatal(err)
}

Copilot uses AI. Check for mistakes.
Comment thread integration-tests.md Outdated
Comment on lines +1 to +6
# 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).

Copilot AI Feb 28, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment thread Makefile
Comment thread Makefile
@Sefi4 Sefi4 force-pushed the sefitufan/add-golangci-lint-config branch from 3b08a2b to aaeb408 Compare February 28, 2026 10:17
- 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>
@Sefi4 Sefi4 force-pushed the sefitufan/add-golangci-lint-config branch from aaeb408 to 162fc00 Compare February 28, 2026 10:20
Copilot AI review requested due to automatic review settings February 28, 2026 10:20

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +23 to +24

"github.com/go-jose/go-jose/v4/testutils/require"

Copilot AI Feb 28, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
"github.com/go-jose/go-jose/v4/testutils/require"

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is unrelated to this PR. I'll fix it in a follow-up PR

Comment thread go.mod
Comment on lines 5 to +15
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

Copilot AI Feb 28, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
@dorser dorser merged commit 945ebe4 into micromize-dev:main Mar 1, 2026
9 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add CI workflow for pull requests (build, test, lint) Add make lint, make clean, and make fmt targets Add .golangci.yml linter configuration

3 participants