Skip to content

Commit e3160b0

Browse files
authored
GolangCI-Lint Added with Happy Linter (#7)
1 parent e570568 commit e3160b0

File tree

9 files changed

+50
-6
lines changed

9 files changed

+50
-6
lines changed

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ jobs:
1515
with:
1616
go-version: 1.14
1717

18+
- name: Lint
19+
run: make lint
20+
1821
- name: Run GoReleaser
1922
uses: goreleaser/goreleaser-action@v2
2023
with:

.golangci.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
linters:
2+
auto-fix: false
3+
enable:
4+
- errcheck
5+
- goimports
6+
- golint
7+
- gosec
8+
- misspell
9+
- scopelint
10+
- unconvert
11+
- unparam
12+
- interfacer
13+
- nakedret
14+
- gocyclo
15+
- dupl
16+
- goconst
17+
- lll
18+
run:
19+
linters-settings:
20+
errcheck:
21+
check-type-assertions: true
22+
lll:
23+
line-length: 250
24+
dupl:
25+
threshold: 400

Makefile

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1-
.PHONY: all build
1+
.PHONY: all build lint
22
all: build
33

44
build:
55
go build -o bin/kubectl-operator
66

77
install: build
88
install bin/kubectl-operator $(shell go env GOPATH)/bin
9+
10+
GOLANGCI_LINT_VER = "1.29.0"
11+
lint:
12+
# scripts/golangci-lint-check.sh
13+
ifneq (${GOLANGCI_LINT_VER}, "$(shell ./bin/golangci-lint --version 2>/dev/null | cut -b 27-32)")
14+
@echo "golangci-lint missing or not version '${GOLANGCI_LINT_VER}', downloading..."
15+
curl -sSfL "https://raw.githubusercontent.com/golangci/golangci-lint/v${GOLANGCI_LINT_VER}/install.sh" | sh -s -- -b ./bin "v${GOLANGCI_LINT_VER}"
16+
endif
17+
./bin/golangci-lint --timeout 3m run

internal/cmd/catalog_list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func newCatalogListCmd(cfg *action.Configuration) *cobra.Command {
4949
if allNamespaces {
5050
ns = "\t" + cs.Namespace
5151
}
52-
age := time.Now().Sub(cs.CreationTimestamp.Time)
52+
age := time.Since(cs.CreationTimestamp.Time)
5353
_, _ = fmt.Fprintf(tw, "%s%s\t%s\t%s\t%s\t%s\n", cs.Name, ns, cs.Spec.DisplayName, cs.Spec.SourceType, cs.Spec.Publisher, duration.HumanDuration(age))
5454
}
5555
_ = tw.Flush()

internal/cmd/operator_list.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func newOperatorListCmd(cfg *action.Configuration) *cobra.Command {
5555
if allNamespaces {
5656
ns = "\t" + sub.Namespace
5757
}
58-
age := time.Now().Sub(sub.CreationTimestamp.Time)
58+
age := time.Since(sub.CreationTimestamp.Time)
5959
_, _ = fmt.Fprintf(tw, "%s%s\t%s\t%s\t%s\t%s\t%s\n", sub.Spec.Package, ns, sub.Name, sub.Status.InstalledCSV, sub.Status.CurrentCSV, sub.Status.State, duration.HumanDuration(age))
6060
}
6161
_ = tw.Flush()

internal/cmd/operator_list_available.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func newOperatorListAvailableCmd(cfg *action.Configuration) *cobra.Command {
4848
tw := tabwriter.NewWriter(os.Stdout, 3, 4, 2, ' ', 0)
4949
_, _ = fmt.Fprintf(tw, "NAME\tCATALOG\tCHANNEL\tLATEST CSV\tAGE\n")
5050
for _, op := range operators {
51-
age := time.Now().Sub(op.CreationTimestamp.Time)
51+
age := time.Since(op.CreationTimestamp.Time)
5252
for _, ch := range op.Status.Channels {
5353
_, _ = fmt.Fprintf(tw, "%s\t%s\t%s\t%s\t%s\n", op.Name, op.Status.CatalogSourceDisplayName, ch.Name, ch.CurrentCSV, duration.HumanDuration(age))
5454
}

internal/pkg/action/operator_install.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ func (i *OperatorInstall) BindFlags(fs *pflag.FlagSet) {
5151
fs.BoolVarP(&i.CreateOperatorGroup, "create-operator-group", "C", false, "create operator group if necessary")
5252

5353
fs.VarP(&i.InstallMode, "install-mode", "i", "install mode")
54-
fs.MarkHidden("install-mode")
54+
err := fs.MarkHidden("install-mode")
55+
if err != nil {
56+
panic(`requested flag "install-mode" missing`)
57+
}
5558
}
5659

5760
func (i *OperatorInstall) Run(ctx context.Context) (*v1alpha1.ClusterServiceVersion, error) {
@@ -135,6 +138,7 @@ func (i *OperatorInstall) getPackageChannel(pm *operatorsv1.PackageManifest) (*o
135138
}
136139
var packageChannel *operatorsv1.PackageChannel
137140
for _, ch := range pm.Status.Channels {
141+
ch := ch
138142
if ch.Name == i.Channel {
139143
packageChannel = &ch
140144
}
@@ -308,7 +312,7 @@ func guessStartingCSV(csvNameExample, desiredVersion string) string {
308312

309313
const (
310314
operatorNameRegexp = `[a-z0-9]([-a-z0-9]*[a-z0-9])?`
311-
semverRegexp = `(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)\.(?P<patch>0|[1-9]\d*)(?:-(?P<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?P<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?`
315+
semverRegexp = `(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)\.(?P<patch>0|[1-9]\d*)(?:-(?P<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?P<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?` //nolint:lll
312316
)
313317

314318
var csvNameRegexp = regexp.MustCompile(`^(` + operatorNameRegexp + `).(v?)(` + semverRegexp + `)$`)

internal/pkg/action/operator_uninstall.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ func (u *OperatorUninstall) Run(ctx context.Context) error {
4949

5050
var sub *v1alpha1.Subscription
5151
for _, s := range subs.Items {
52+
s := s
5253
if u.Package == s.Spec.Package {
5354
sub = &s
5455
break
@@ -85,6 +86,7 @@ func (u *OperatorUninstall) Run(ctx context.Context) error {
8586
return fmt.Errorf("list operatorgroups: %v", err)
8687
}
8788
for _, og := range ogs.Items {
89+
og := og
8890
if err := u.config.Client.Delete(ctx, &og); err != nil {
8991
return fmt.Errorf("delete operatorgroup %q: %v", og.Name, err)
9092
}

internal/pkg/action/operator_upgrade.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ func (u *OperatorUpgrade) Run(ctx context.Context) (*v1alpha1.ClusterServiceVers
3939

4040
var sub *v1alpha1.Subscription
4141
for _, s := range subs.Items {
42+
s := s
4243
if u.Package == s.Spec.Package {
4344
sub = &s
4445
break

0 commit comments

Comments
 (0)