Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌱 make golangci-lint config consistent across repos #255

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .bingo/Variables.mk
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ $(GINKGO): $(BINGO_DIR)/ginkgo.mod
@echo "(re)installing $(GOBIN)/ginkgo-v2.12.0"
@cd $(BINGO_DIR) && GOWORK=off $(GO) build -mod=mod -modfile=ginkgo.mod -o=$(GOBIN)/ginkgo-v2.12.0 "github.com/onsi/ginkgo/v2/ginkgo"

GOLANGCI_LINT := $(GOBIN)/golangci-lint-v1.53.3
Copy link
Contributor

@tmshort tmshort Apr 25, 2024

Choose a reason for hiding this comment

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

Why do I really want these version numbers to be variables?

Copy link
Member Author

Choose a reason for hiding this comment

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

This file is auto-managed by the bingo CLI. These variables are referenced in our Makefile so that we can use a consistent name as we bump the version.

And the reason the version number is in the name of the binary is that bingo stores the binary in GOBIN and can thus use different versions of the same tool across different projects without having to re-build separately for each project.

GOLANGCI_LINT := $(GOBIN)/golangci-lint-v1.57.2
$(GOLANGCI_LINT): $(BINGO_DIR)/golangci-lint.mod
@# Install binary/ries using Go 1.14+ build command. This is using bwplotka/bingo-controlled, separate go module with pinned dependencies.
@echo "(re)installing $(GOBIN)/golangci-lint-v1.53.3"
@cd $(BINGO_DIR) && GOWORK=off $(GO) build -mod=mod -modfile=golangci-lint.mod -o=$(GOBIN)/golangci-lint-v1.53.3 "github.com/golangci/golangci-lint/cmd/golangci-lint"
@echo "(re)installing $(GOBIN)/golangci-lint-v1.57.2"
@cd $(BINGO_DIR) && GOWORK=off $(GO) build -mod=mod -modfile=golangci-lint.mod -o=$(GOBIN)/golangci-lint-v1.57.2 "github.com/golangci/golangci-lint/cmd/golangci-lint"

GORELEASER := $(GOBIN)/goreleaser-v1.16.2
$(GORELEASER): $(BINGO_DIR)/goreleaser.mod
Expand Down
6 changes: 4 additions & 2 deletions .bingo/golangci-lint.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module _ // Auto generated by https://github.com/bwplotka/bingo. DO NOT EDIT

go 1.20
go 1.21

require github.com/golangci/golangci-lint v1.53.3 // cmd/golangci-lint
toolchain go1.22.2

require github.com/golangci/golangci-lint v1.57.2 // cmd/golangci-lint
161 changes: 161 additions & 0 deletions .bingo/golangci-lint.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .bingo/variables.env
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ CONTROLLER_GEN="${GOBIN}/controller-gen-v0.12.0"

GINKGO="${GOBIN}/ginkgo-v2.12.0"

GOLANGCI_LINT="${GOBIN}/golangci-lint-v1.53.3"
GOLANGCI_LINT="${GOBIN}/golangci-lint-v1.57.2"

GORELEASER="${GOBIN}/goreleaser-v1.16.2"

Expand Down
42 changes: 34 additions & 8 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
########
# NOTE
#
# This file is duplicated in the following repos:
# - operator-framework/kubectl-operator
# - operator-framework/catalogd
# - operator-framework/operator-controller
# - operator-framework/rukpak
#
# If you are making a change, please make it in ALL
# of the above repositories!
#
# TODO: Find a way to have a shared golangci config.
Copy link
Contributor

Choose a reason for hiding this comment

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

+1

Copy link
Contributor

Choose a reason for hiding this comment

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

vendor and symlink?

########

run:
# Default timeout is 1m, up to give more room
timeout: 4m
Expand All @@ -7,16 +22,14 @@ linters:
- asciicheck
- bodyclose
- errorlint
- ginkgolinter
- gci
- gofmt
- goimports
- gosec
- importas
- misspell
- nestif
- nonamedreturns
- prealloc
- revive
- stylecheck
- tparallel
- unconvert
Expand All @@ -25,6 +38,18 @@ linters:
- whitespace

linters-settings:
gci:
sections:
- standard
- dot
- default
- prefix(github.com/operator-framework)

# TODO: change this to `localmodule` when golangci-lint
# is updated to 1.58+
- prefix(github.com/operator-framework/catalogd)
custom-order: true

errorlint:
errorf: false

Expand All @@ -42,10 +67,11 @@ linters-settings:
alias: $1$2
- pkg: sigs.k8s.io/controller-runtime
alias: ctrl
- pkg: github.com/operator-framework/rukpak/api/v1alpha1
alias: rukpakv1alpha1
goimports:
local-prefixes: github.com/operator-framework/catalogd
- pkg: github.com/operator-framework/rukpak/api/v1alpha2
alias: rukpakv1alpha2
- pkg: github.com/blang/semver/v4
alias: bsemver

output:
format: tab
formats:
- format: tab
2 changes: 1 addition & 1 deletion api/core/v1alpha1/catalog_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func TestPollIntervalCELValidationRules(t *testing.T) {
},
} {
t.Run(name, func(t *testing.T) {
obj, err := runtime.DefaultUnstructuredConverter.ToUnstructured(&tc.spec)
obj, err := runtime.DefaultUnstructuredConverter.ToUnstructured(&tc.spec) //nolint:gosec
require.NoError(t, err)
errs := validator(obj, nil)
require.Equal(t, len(tc.wantErrs), len(errs))
Expand Down
14 changes: 4 additions & 10 deletions cmd/manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,19 @@ import (
"path/filepath"
"time"

// Import all Kubernetes client auth plugins (e.g. Azure, GCP, OIDC, etc.)
// to ensure that exec-entrypoint and run can make use of them.
"k8s.io/client-go/metadata"
_ "k8s.io/client-go/plugin/pkg/client/auth"

"github.com/spf13/pflag"
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/metadata"
_ "k8s.io/client-go/plugin/pkg/client/auth"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/healthz"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
"sigs.k8s.io/controller-runtime/pkg/metrics"
metricsserver "sigs.k8s.io/controller-runtime/pkg/metrics/server"

"github.com/spf13/pflag"

"github.com/operator-framework/catalogd/api/core/v1alpha1"
"github.com/operator-framework/catalogd/internal/garbagecollection"
"github.com/operator-framework/catalogd/internal/source"
"github.com/operator-framework/catalogd/internal/third_party/server"
Expand All @@ -49,9 +46,6 @@ import (
"github.com/operator-framework/catalogd/pkg/features"
catalogdmetrics "github.com/operator-framework/catalogd/pkg/metrics"
"github.com/operator-framework/catalogd/pkg/storage"

//+kubebuilder:scaffold:imports
"github.com/operator-framework/catalogd/api/core/v1alpha1"
)

var (
Expand Down
3 changes: 1 addition & 2 deletions pkg/controllers/core/catalog_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@ import (
"time"

"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"
"github.com/stretchr/testify/assert"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
ctrl "sigs.k8s.io/controller-runtime"

"github.com/google/go-cmp/cmp/cmpopts"

catalogdv1alpha1 "github.com/operator-framework/catalogd/api/core/v1alpha1"
"github.com/operator-framework/catalogd/internal/source"
"github.com/operator-framework/catalogd/pkg/storage"
Expand Down
4 changes: 3 additions & 1 deletion pkg/storage/localdir_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ import (
"path/filepath"
"testing/fstest"

"github.com/google/go-cmp/cmp"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"github.com/google/go-cmp/cmp"

"github.com/operator-framework/operator-registry/alpha/declcfg"
)

Expand Down
1 change: 1 addition & 0 deletions test/e2e/e2e_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"k8s.io/client-go/kubernetes"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/rest"
Expand Down
3 changes: 2 additions & 1 deletion test/e2e/unpack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import (
"os"
"strings"

"github.com/google/go-cmp/cmp"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

"github.com/google/go-cmp/cmp"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand Down
Loading