Skip to content
This repository was archived by the owner on May 9, 2025. It is now read-only.

Commit 63a0a69

Browse files
authored
feat: applying lint and fixing the lint issues (#86)
1 parent 0e6cac5 commit 63a0a69

File tree

22 files changed

+281
-94
lines changed

22 files changed

+281
-94
lines changed

.github/workflows/tests.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: tests
1+
name: tests and linting
22

33
on:
44
pull_request:
@@ -32,5 +32,7 @@ jobs:
3232
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
3333
restore-keys: |
3434
${{ runner.os }}-go-
35+
- name: Run lint
36+
run: make lint
3537
- name: Run tests
3638
run: make test

.golangci.yaml

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
run:
2+
go: "1.21"
3+
timeout: 10m
4+
tests: false
5+
allow-parallel-runners: true
6+
skip-dirs:
7+
- "./*/mock"
8+
skip-files:
9+
- "pkg/providers/fakes/fake_provider.go"
10+
11+
linters-settings:
12+
funlen:
13+
lines: 150
14+
statements: 60
15+
staticcheck:
16+
go: "1.21"
17+
stylecheck:
18+
go: "1.21"
19+
cyclop:
20+
max-complexity: 20
21+
skip-tests: true
22+
gosec:
23+
exclude-generated: true
24+
lll:
25+
line-length: 150
26+
misspell:
27+
locale: US
28+
govet:
29+
check-shadowing: true
30+
nolintlint:
31+
allow-unused: false
32+
require-explanation: true
33+
require-specific: false
34+
varnamelen:
35+
ignore-names:
36+
- err
37+
- wg
38+
- fs
39+
- id
40+
- vm
41+
- ns
42+
- ip
43+
44+
issues:
45+
max-same-issues: 0
46+
max-issues-per-linter: 0
47+
exclude-rules:
48+
- text: "should not use dot imports|don't use an underscore in package name"
49+
linters:
50+
- golint
51+
- source: "https://"
52+
linters:
53+
- lll
54+
- path: pkg/defaults/
55+
linters:
56+
- lll
57+
- path: _test\.go
58+
linters:
59+
- goerr113
60+
- gocyclo
61+
- errcheck
62+
- gosec
63+
- dupl
64+
- funlen
65+
- scopelint
66+
- testpackage
67+
- goconst
68+
- godox
69+
- path: internal/version/
70+
linters:
71+
- gochecknoglobals
72+
- path: internal/command/
73+
linters:
74+
- exhaustivestruct
75+
- lll
76+
- wrapcheck
77+
- source: "// .* #\\d+"
78+
linters:
79+
- godox
80+
- path: test/e2e/
81+
linters:
82+
- goerr113
83+
- gomnd
84+
# remove this once https://github.com/golangci/golangci-lint/issues/2649 is closed
85+
- path: /
86+
linters:
87+
- typecheck
88+
89+
linters:
90+
enable-all: true
91+
disable:
92+
- gci
93+
- depguard
94+
- exhaustivestruct
95+
- golint
96+
- interfacer
97+
- ireturn
98+
- maligned
99+
- nilnil
100+
- scopelint
101+
- tagliatelle
102+
- gomoddirectives
103+
- varcheck
104+
- nosnakecase
105+
- structcheck
106+
- ifshort
107+
- deadcode
108+
- forbidigo
109+
- prealloc
110+
- gochecknoinits
111+
- exhaustruct
112+
- goerr113
113+
- govet
114+
- nonamedreturns
115+
- varnamelen
116+
- wrapcheck
117+
- staticcheck
118+
- gochecknoglobals
119+
- paralleltest
120+
- wsl

Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ fmt: ## Run go fmt against code.
5757
vet: ## Run go vet against code.
5858
go vet ./...
5959

60+
.PHONY: lint
61+
lint: golangci-lint ## Run golangci-lint.
62+
$(GOLANGCI_LINT) run
63+
6064
.PHONY: test
6165
test: manifests generate fmt vet envtest ## Run tests.
6266
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./... -coverprofile cover.out
@@ -137,6 +141,7 @@ $(LOCALBIN):
137141
mkdir -p $(LOCALBIN)
138142

139143
## Tool Binaries
144+
GOLANGCI_LINT ?= $(LOCALBIN)/golangci-lint
140145
KUSTOMIZE ?= $(LOCALBIN)/kustomize
141146
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
142147
ENVTEST ?= $(LOCALBIN)/setup-envtest
@@ -146,6 +151,7 @@ GEN_CRD_API_REFERENCE_DOCS ?= $(LOCALBIN)/gen-crd-api-reference-docs
146151
KUSTOMIZE_VERSION ?= v3.8.7
147152
CONTROLLER_TOOLS_VERSION ?= v0.9.2
148153
GEN_API_REF_DOCS_VERSION ?= e327d0730470cbd61b06300f81c5fcf91c23c113
154+
GOLANGCI_LINT_VERSION ?= v1.55.2
149155

150156
KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
151157
.PHONY: kustomize
@@ -178,3 +184,8 @@ generate-license:
178184
gen-crd-api-reference-docs: $(GEN_CRD_API_REFERENCE_DOCS)
179185
$(GEN_CRD_API_REFERENCE_DOCS): $(LOCALBIN)
180186
GOBIN=$(LOCALBIN) go install github.com/ahmetb/gen-crd-api-reference-docs@$(GEN_API_REF_DOCS_VERSION)
187+
188+
.PHONY: golangci-lint
189+
golangci-lint: $(GOLANGCI_LINT)
190+
$(GOLANGCI_LINT): $(LOCALBIN)
191+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s $(GOLANGCI_LINT_VERSION)

apis/delivery/v1alpha1/condition_types.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@
55
package v1alpha1
66

77
const (
8-
// PatchFailedReason is used when we couldn't patch an object.
9-
PatchFailedReason = "PatchFailed"
10-
118
// SnapshotGetFailedReason is used when the needed snapshot does not exist.
129
SnapshotGetFailedReason = "SnapshotGetFailed"
1310

@@ -22,7 +19,4 @@ const (
2219

2320
// CreatePullRequestFailedReason is used when creating a pull request failed.
2421
CreatePullRequestFailedReason = "CreatePullRequestFailed"
25-
26-
// GitRepositoryCreateFailedReason is used when creating a git repository failed.
27-
GitRepositoryCreateFailedReason = "GitRepositoryCreateFailed"
2822
)

apis/delivery/v1alpha1/constants.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,7 @@ const (
44
// StatusCheckName defines the name of the check a PullRequest will have.
55
StatusCheckName = "mpas/validation-check"
66
)
7+
8+
const (
9+
LevelDebug = 4
10+
)

apis/delivery/v1alpha1/groupversion_info.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ import (
1313
)
1414

1515
var (
16-
// GroupVersion is group version used to register these objects
16+
// GroupVersion is group version used to register these objects.
1717
GroupVersion = schema.GroupVersion{Group: "delivery.ocm.software", Version: "v1alpha1"}
1818

19-
// SchemeBuilder is used to add go types to the GroupVersionKind scheme
19+
// SchemeBuilder is used to add go types to the GroupVersionKind scheme.
2020
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
2121

2222
// AddToScheme adds the types in this group-version to the given scheme.

apis/delivery/v1alpha1/sync_types.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ type PullRequestTemplate struct {
3333
Base string `json:"base,omitempty"`
3434
}
3535

36-
// SyncSpec defines the desired state of Sync
36+
// SyncSpec defines the desired state of Sync.
3737
type SyncSpec struct {
3838
SnapshotRef v1.LocalObjectReference `json:"snapshotRef"`
3939
RepositoryRef meta.NamespacedObjectReference `json:"repositoryRef"`
@@ -48,7 +48,7 @@ type SyncSpec struct {
4848
PullRequestTemplate PullRequestTemplate `json:"pullRequestTemplate,omitempty"`
4949
}
5050

51-
// SyncStatus defines the observed state of Sync
51+
// SyncStatus defines the observed state of Sync.
5252
type SyncStatus struct {
5353
Digest string `json:"digest,omitempty"`
5454

@@ -95,7 +95,7 @@ func (in Sync) GetRequeueAfter() time.Duration {
9595
//+kubebuilder:object:root=true
9696
//+kubebuilder:subresource:status
9797

98-
// Sync is the Schema for the syncs API
98+
// Sync is the Schema for the syncs API.
9999
type Sync struct {
100100
metav1.TypeMeta `json:",inline"`
101101
metav1.ObjectMeta `json:"metadata,omitempty"`
@@ -106,7 +106,7 @@ type Sync struct {
106106

107107
//+kubebuilder:object:root=true
108108

109-
// SyncList contains a list of Sync
109+
// SyncList contains a list of Sync.
110110
type SyncList struct {
111111
metav1.TypeMeta `json:",inline"`
112112
metav1.ListMeta `json:"metadata,omitempty"`

apis/mpas/v1alpha1/groupversion_info.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ import (
1313
)
1414

1515
var (
16-
// GroupVersion is group version used to register these objects
16+
// GroupVersion is group version used to register these objects.
1717
GroupVersion = schema.GroupVersion{Group: "mpas.ocm.software", Version: "v1alpha1"}
1818

19-
// SchemeBuilder is used to add go types to the GroupVersionKind scheme
19+
// SchemeBuilder is used to add go types to the GroupVersionKind scheme.
2020
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion}
2121

2222
// AddToScheme adds the types in this group-version to the given scheme.

apis/mpas/v1alpha1/repository_types.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ var (
2828
ExistingRepositoryPolicyFail ExistingRepositoryPolicy = "fail"
2929
)
3030

31-
// RepositorySpec defines the desired state of Repository
31+
// RepositorySpec defines the desired state of Repository.
3232
type RepositorySpec struct {
3333
//+required
3434
Provider string `json:"provider"`
@@ -73,7 +73,7 @@ type CommitTemplate struct {
7373
Name string `json:"name"`
7474
}
7575

76-
// RepositoryStatus defines the observed state of Repository
76+
// RepositoryStatus defines the observed state of Repository.
7777
type RepositoryStatus struct {
7878
// ObservedGeneration is the last reconciled generation.
7979
// +optional
@@ -143,7 +143,7 @@ func (in *Repository) SetObservedGeneration(v int64) {
143143
//+kubebuilder:object:root=true
144144
//+kubebuilder:subresource:status
145145

146-
// Repository is the Schema for the repositories API
146+
// Repository is the Schema for the repositories API.
147147
type Repository struct {
148148
metav1.TypeMeta `json:",inline"`
149149
metav1.ObjectMeta `json:"metadata,omitempty"`
@@ -154,7 +154,7 @@ type Repository struct {
154154

155155
//+kubebuilder:object:root=true
156156

157-
// RepositoryList contains a list of Repository
157+
// RepositoryList contains a list of Repository.
158158
type RepositoryList struct {
159159
metav1.TypeMeta `json:",inline"`
160160
metav1.ListMeta `json:"metadata,omitempty"`

config/crd/bases/delivery.ocm.software_syncs.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ spec:
1818
- name: v1alpha1
1919
schema:
2020
openAPIV3Schema:
21-
description: Sync is the Schema for the syncs API
21+
description: Sync is the Schema for the syncs API.
2222
properties:
2323
apiVersion:
2424
description: 'APIVersion defines the versioned schema of this representation
@@ -33,7 +33,7 @@ spec:
3333
metadata:
3434
type: object
3535
spec:
36-
description: SyncSpec defines the desired state of Sync
36+
description: SyncSpec defines the desired state of Sync.
3737
properties:
3838
automaticPullRequestCreation:
3939
type: boolean
@@ -106,7 +106,7 @@ spec:
106106
- subPath
107107
type: object
108108
status:
109-
description: SyncStatus defines the observed state of Sync
109+
description: SyncStatus defines the observed state of Sync.
110110
properties:
111111
conditions:
112112
items:

0 commit comments

Comments
 (0)