From f66374f6a87f8c2d67932d6b0249bae358b70f93 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Sat, 8 Apr 2023 20:03:27 +0200 Subject: [PATCH] golangci-lint: enable importas linter to force consistent aliases This enforces the github.com/containerd/containerd/errdefs package to be aliased as "cerrdefs". Any other alias (or no alias used) results in a linting failure: integration/container/pause_test.go:9:2: import "github.com/containerd/containerd/errdefs" imported as "c8derrdefs" but must be "cerrdefs" according to config (importas) c8derrdefs "github.com/containerd/containerd/errdefs" ^ Signed-off-by: Sebastiaan van Stijn --- hack/validate/golangci-lint.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/hack/validate/golangci-lint.yml b/hack/validate/golangci-lint.yml index 7ca17133ea..618fd60cf3 100644 --- a/hack/validate/golangci-lint.yml +++ b/hack/validate/golangci-lint.yml @@ -5,6 +5,7 @@ linters: - gosec - gosimple - govet + - importas - ineffassign - misspell - revive @@ -24,6 +25,16 @@ linters: - docs linters-settings: + importas: + # Do not allow unaliased imports of aliased packages. + no-unaliased: true + + alias: + # Enforce alias to prevent it accidentally being used instead of our + # own errdefs package (or vice-versa). + - pkg: github.com/containerd/containerd/errdefs + alias: cerrdefs + govet: check-shadowing: false depguard: