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

Commit 638ef71

Browse files
committed
feat: applying lint and fixing the lint issues
1 parent a6f5a3b commit 638ef71

File tree

23 files changed

+284
-94
lines changed

23 files changed

+284
-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: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
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+
nilaway:
31+
nolintlint:
32+
allow-unused: false
33+
require-explanation: true
34+
require-specific: false
35+
varnamelen:
36+
ignore-names:
37+
- err
38+
- wg
39+
- fs
40+
- id
41+
- vm
42+
- ns
43+
- ip
44+
45+
issues:
46+
max-same-issues: 0
47+
max-issues-per-linter: 0
48+
exclude-rules:
49+
- text: "should not use dot imports|don't use an underscore in package name"
50+
linters:
51+
- golint
52+
- source: "https://"
53+
linters:
54+
- lll
55+
- path: pkg/defaults/
56+
linters:
57+
- lll
58+
- path: _test\.go
59+
linters:
60+
- goerr113
61+
- gocyclo
62+
- errcheck
63+
- gosec
64+
- dupl
65+
- funlen
66+
- scopelint
67+
- testpackage
68+
- goconst
69+
- godox
70+
- path: internal/version/
71+
linters:
72+
- gochecknoglobals
73+
- path: internal/command/
74+
linters:
75+
- exhaustivestruct
76+
- lll
77+
- wrapcheck
78+
- source: "// .* #\\d+"
79+
linters:
80+
- godox
81+
- path: test/e2e/
82+
linters:
83+
- goerr113
84+
- gomnd
85+
# remove this once https://github.com/golangci/golangci-lint/issues/2649 is closed
86+
- path: /
87+
linters:
88+
- typecheck
89+
90+
linters:
91+
enable-all: true
92+
disable:
93+
- gci
94+
- depguard
95+
- exhaustivestruct
96+
- golint
97+
- interfacer
98+
- ireturn
99+
- maligned
100+
- nilnil
101+
- scopelint
102+
- tagliatelle
103+
- gomoddirectives
104+
- varcheck
105+
- nosnakecase
106+
- structcheck
107+
- ifshort
108+
- deadcode
109+
- forbidigo
110+
- prealloc
111+
- gochecknoinits
112+
- exhaustruct
113+
- goerr113
114+
- govet
115+
- nonamedreturns
116+
- varnamelen
117+
- wrapcheck
118+
- staticcheck
119+
- gochecknoglobals
120+
- paralleltest
121+
- 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
@@ -130,13 +134,15 @@ $(LOCALBIN):
130134
mkdir -p $(LOCALBIN)
131135

132136
## Tool Binaries
137+
GOLANGCI_LINT ?= $(LOCALBIN)/golangci-lint
133138
KUSTOMIZE ?= $(LOCALBIN)/kustomize
134139
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
135140
ENVTEST ?= $(LOCALBIN)/setup-envtest
136141

137142
## Tool Versions
138143
KUSTOMIZE_VERSION ?= v3.8.7
139144
CONTROLLER_TOOLS_VERSION ?= v0.9.2
145+
GOLANGCI_LINT_VERSION ?= v1.55.2
140146

141147
KUSTOMIZE_INSTALL_SCRIPT ?= "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh"
142148
.PHONY: kustomize
@@ -163,3 +169,8 @@ generate-license:
163169
$$f \
164170
--skip-unrecognised; \
165171
done
172+
173+
.PHONY: golangci-lint
174+
golangci-lint: $(GOLANGCI_LINT)
175+
$(GOLANGCI_LINT): $(LOCALBIN)
176+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s $(GOLANGCI_LINT_VERSION)

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ It uses [Controllers](https://kubernetes.io/docs/concepts/architecture/controlle
5252
which provides a reconcile function responsible for synchronizing resources untile the desired state is reached on the cluster
5353

5454
### Test It Out
55+
5556
1. Install the CRDs into the cluster:
5657

5758
```sh
@@ -67,6 +68,7 @@ make run
6768
**NOTE:** You can also run this in one step by running: `make install run`
6869

6970
### Modifying the API definitions
71+
7072
If you are editing the API definitions, generate the manifests such as CRs or CRDs using:
7173

7274
```sh

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"`

0 commit comments

Comments
 (0)