Skip to content
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
221 changes: 109 additions & 112 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,116 +1,113 @@
run:
deadline: 5m

linters-settings:
goimports:
local-prefixes: github.com/vmware-tanzu
importas:
alias:
- pkg: k8s.io/api/core/v1
alias: corev1
- pkg: k8s.io/apimachinery/pkg/apis/meta/v1
alias: metav1

- pkg: github.com/vmware-tanzu/image-registry-operator-api/api/v1alpha1
alias: imgregopv1a1
- pkg: github.com/vmware-tanzu/image-registry-operator-api/api/v1alpha2
alias: imgregopv1

depguard:
rules:
main:
list-mode: lax # allow unless explicitly denied
files:
- $all
- "!$test"
deny:
- pkg: io/ioutil
desc: "replaced by io and os packages since Go 1.16: https://tip.golang.org/doc/go1.16#ioutil"
- pkg: github.com/pkg/errors
desc: "replaced by stdlib errors package since Go.13: https://go.dev/blog/go1.13-errors"
- pkg: k8s.io/utils
desc: "replaced by internal packages like pkg/util/ptr"
- pkg: testing
desc: "do not import testing packages in non-test sources"
- pkg: github.com/onsi/ginkgo$
desc: "do not import testing packages in non-test sources"
- pkg: github.com/onsi/ginkgo/v2
desc: "do not import testing packages in non-test sources"
- pkg: github.com/onsi/gomega
desc: "do not import testing packages in non-test sources"
test:
list-mode: lax # allow unless explicitly denied
files:
- $test
deny:
- pkg: io/ioutil
desc: "replaced by io and os packages since Go 1.16: https://tip.golang.org/doc/go1.16#ioutil"
- pkg: github.com/pkg/errors
desc: "replaced by stdlib errors package since Go.13: https://go.dev/blog/go1.13-errors"
- pkg: k8s.io/utils
desc: "replaced by internal packages like pkg/util/ptr"
- pkg: github.com/onsi/ginkgo$
desc: "replaced by github.com/onsi/ginkgo/v2"

version: "2"
linters:
disable-all: true
default: none
enable:
- asciicheck
- bodyclose
- depguard
- dogsled
- errcheck
- goconst
- gocritic
- gocyclo
- godot
- gofmt
- goimports
- goprintffuncname
- gosec
- gosimple
- govet
- importas
- ineffassign
- nakedret
- nilerr
- nolintlint
- prealloc
- revive
- rowserrcheck
- staticcheck
- stylecheck
- typecheck
- unconvert
- unparam
- unused

- asciicheck
- bodyclose
- depguard
- dogsled
- errcheck
- goconst
- gocritic
- gocyclo
- godot
- goprintffuncname
- gosec
- govet
- importas
- ineffassign
- nakedret
- nilerr
- nolintlint
- prealloc
- revive
- rowserrcheck
- staticcheck
- unconvert
- unparam
- unused
settings:
depguard:
rules:
main:
list-mode: lax
files:
- $all
- '!$test'
deny:
- pkg: io/ioutil
desc: 'replaced by io and os packages since Go 1.16: https://tip.golang.org/doc/go1.16#ioutil'
- pkg: github.com/pkg/errors
desc: 'replaced by stdlib errors package since Go.13: https://go.dev/blog/go1.13-errors'
- pkg: k8s.io/utils
desc: replaced by internal packages like pkg/util/ptr
- pkg: testing
desc: do not import testing packages in non-test sources
- pkg: github.com/onsi/ginkgo$
desc: do not import testing packages in non-test sources
- pkg: github.com/onsi/ginkgo/v2
desc: do not import testing packages in non-test sources
- pkg: github.com/onsi/gomega
desc: do not import testing packages in non-test sources
test:
list-mode: lax
files:
- $test
deny:
- pkg: io/ioutil
desc: 'replaced by io and os packages since Go 1.16: https://tip.golang.org/doc/go1.16#ioutil'
- pkg: github.com/pkg/errors
desc: 'replaced by stdlib errors package since Go.13: https://go.dev/blog/go1.13-errors'
- pkg: k8s.io/utils
desc: replaced by internal packages like pkg/util/ptr
- pkg: github.com/onsi/ginkgo$
desc: replaced by github.com/onsi/ginkgo/v2
importas:
alias:
- pkg: k8s.io/api/core/v1
alias: corev1
- pkg: k8s.io/apimachinery/pkg/apis/meta/v1
alias: metav1
- pkg: github.com/vmware-tanzu/image-registry-operator-api/api/v1alpha1
alias: imgregopv1a1
- pkg: github.com/vmware-tanzu/image-registry-operator-api/api/v1alpha2
alias: imgregopv1
exclusions:
generated: lax
rules:
- linters:
- revive
text: .*should have comment.* or be unexported
- path: _conversion.go
text: .*use underscores in Go names
- path: _conversion.go
text: 'G103: Use of unsafe calls should be audited'
- path: _conversion.go
text: .*receiver name
- path: _test.go
text: should not use dot imports
- path: (.+)\.go$
text: 'ST1000: at least one file in a package should have a package comment'
paths:
- .*generated.*\.go
- third_party$
- builtin$
- examples$
issues:
max-same-issues: 0
max-issues-per-linter: 0
# Disable the default golangci exclusions so no issues are skipped.
# This will help reviewers to focus on reviewing the most relevant changes in
# the PRs and avoid nitpicking.
exclude-use-default: false
exclude-files:
- ".*generated.*\\.go"
exclude:
# TODO: Remove the following exclusions over time once we have fixed those.
- "ST1000: at least one file in a package should have a package comment"
# List of regexps of issue texts to exclude, empty list by default.
exclude-rules:
- linters:
- revive
text: ".*should have comment.* or be unexported"
# Ignore underscores in conversion function names as required by K8s API.
- path: "_conversion.go"
text: ".*use underscores in Go names"
# Ignore unsafe.Pointer() calls used in conversion functions.
- path: "_conversion.go"
text: "G103: Use of unsafe calls should be audited"
# Ignore different receiver names in conversion functions (e.g. src vs dst).
- path: "_conversion.go"
text: ".*receiver name"
# Dot imports for gomega are allowed within test files.
- path: _test.go
text: should not use dot imports
max-same-issues: 0
formatters:
enable:
- gofmt
- goimports
settings:
goimports:
local-prefixes:
- github.com/vmware-tanzu
exclusions:
generated: lax
paths:
- .*generated.*\.go
- third_party$
- builtin$
- examples$
6 changes: 2 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -263,14 +263,12 @@ lint: ## Run all the lint targets
$(MAKE) lint-go-full
$(MAKE) lint-markdown

GOLANGCI_LINT_FLAGS ?= --fast=true
.PHONY: lint-go
lint-go: $(GOLANGCI_LINT) ## Lint codebase
$(GOLANGCI_LINT) run -v $(GOLANGCI_LINT_FLAGS)
$(GOLANGCI_LINT) run -v

.PHONY: lint-go-full
lint-go-full: GOLANGCI_LINT_FLAGS = --fast=false
lint-go-full: lint-go ## Run slower linters to detect possible issues
lint-go-full: lint-go ## Run all linters (alias kept for compatibility)

.PHONY: lint-markdown
lint-markdown: ## Lint the project's markdown
Expand Down
29 changes: 17 additions & 12 deletions api/v1alpha1/contentlibraryitem_conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ import (
imgregopv1 "github.com/vmware-tanzu/image-registry-operator-api/api/v1alpha2"
)

const (
testLibraryRefNameKey = "status.libraryRef.name"
testFakeLibraryName = "fake"
)

func TestContentLibraryItemConversion(t *testing.T) {
t.Run("spoke-hub", func(t *testing.T) {
testCases := []struct {
Expand All @@ -26,18 +31,18 @@ func TestContentLibraryItemConversion(t *testing.T) {
spoke ctrlconversion.Convertible
}{
{
name: "status.libraryRef.name",
name: testLibraryRefNameKey,
spoke: &imgregopv1a1.ContentLibraryItem{
Status: imgregopv1a1.ContentLibraryItemStatus{
ContentLibraryRef: &imgregopv1a1.NameAndKindRef{
Name: "fake",
Name: testFakeLibraryName,
},
},
},
after: &imgregopv1.ContentLibraryItem{},
hub: &imgregopv1.ContentLibraryItem{
Spec: imgregopv1.ContentLibraryItemSpec{
LibraryName: "fake",
LibraryName: testFakeLibraryName,
},
},
},
Expand Down Expand Up @@ -67,13 +72,13 @@ func TestContentLibraryItemListConversion(t *testing.T) {
spoke ctrlconversion.Convertible
}{
{
name: "status.libraryRef.name",
name: testLibraryRefNameKey,
spoke: &imgregopv1a1.ContentLibraryItemList{
Items: []imgregopv1a1.ContentLibraryItem{
{
Status: imgregopv1a1.ContentLibraryItemStatus{
ContentLibraryRef: &imgregopv1a1.NameAndKindRef{
Name: "fake",
Name: testFakeLibraryName,
},
},
},
Expand All @@ -84,7 +89,7 @@ func TestContentLibraryItemListConversion(t *testing.T) {
Items: []imgregopv1.ContentLibraryItem{
{
Spec: imgregopv1.ContentLibraryItemSpec{
LibraryName: "fake",
LibraryName: testFakeLibraryName,
},
},
},
Expand Down Expand Up @@ -116,18 +121,18 @@ func TestClusterContentLibraryItemConversion(t *testing.T) {
spoke ctrlconversion.Convertible
}{
{
name: "status.libraryRef.name",
name: testLibraryRefNameKey,
spoke: &imgregopv1a1.ClusterContentLibraryItem{
Status: imgregopv1a1.ContentLibraryItemStatus{
ContentLibraryRef: &imgregopv1a1.NameAndKindRef{
Name: "fake",
Name: testFakeLibraryName,
},
},
},
after: &imgregopv1.ClusterContentLibraryItem{},
hub: &imgregopv1.ClusterContentLibraryItem{
Spec: imgregopv1.ContentLibraryItemSpec{
LibraryName: "fake",
LibraryName: testFakeLibraryName,
},
},
},
Expand Down Expand Up @@ -157,13 +162,13 @@ func TestClusterContentLibraryItemListConversion(t *testing.T) {
spoke ctrlconversion.Convertible
}{
{
name: "status.libraryRef.name",
name: testLibraryRefNameKey,
spoke: &imgregopv1a1.ClusterContentLibraryItemList{
Items: []imgregopv1a1.ClusterContentLibraryItem{
{
Status: imgregopv1a1.ContentLibraryItemStatus{
ContentLibraryRef: &imgregopv1a1.NameAndKindRef{
Name: "fake",
Name: testFakeLibraryName,
},
},
},
Expand All @@ -174,7 +179,7 @@ func TestClusterContentLibraryItemListConversion(t *testing.T) {
Items: []imgregopv1.ClusterContentLibraryItem{
{
Spec: imgregopv1.ContentLibraryItemSpec{
LibraryName: "fake",
LibraryName: testFakeLibraryName,
},
},
},
Expand Down
8 changes: 5 additions & 3 deletions api/v1alpha1/conversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ import (
imgregopv1 "github.com/vmware-tanzu/image-registry-operator-api/api/v1alpha2"
)

const contentLibraryKind = "ContentLibrary"

func TestFuzzyConversion(t *testing.T) {

testCases := []struct {
Expand All @@ -28,7 +30,7 @@ func TestFuzzyConversion(t *testing.T) {
fuzzerFuncs func(runtimeserializer.CodecFactory) []interface{}
}{
{
name: "ContentLibrary",
name: contentLibraryKind,
hub: &imgregopv1.ContentLibrary{},
spoke: &imgregopv1a1.ContentLibrary{
Status: imgregopv1a1.ContentLibraryStatus{
Expand Down Expand Up @@ -114,7 +116,7 @@ func overrideContentLibraryItemFieldFuncs(_ runtimeserializer.CodecFactory) []in
overrideConditionsSeverity(status.Conditions)
if status.ContentLibraryRef == nil {
status.ContentLibraryRef = &imgregopv1a1.NameAndKindRef{
Kind: "ContentLibrary",
Kind: contentLibraryKind,
}
}
},
Expand Down Expand Up @@ -144,7 +146,7 @@ func overrideContentLibraryItemImportRequestFieldFuncs(_ runtimeserializer.Codec
func(spec *imgregopv1a1.ContentLibraryItemImportRequestSpec, c randfill.Continue) {
c.Fill(spec)
spec.Target.Library.APIVersion = imgregopv1a1.GroupVersion.String()
spec.Target.Library.Kind = "ContentLibrary"
spec.Target.Library.Kind = contentLibraryKind
},
}
}
Expand Down
Loading
Loading