Skip to content

GolangCI-Lint Added with Happy Linter #7

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

Merged
merged 4 commits into from
Aug 6, 2020
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
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ jobs:
with:
go-version: 1.14

- name: Lint
run: make lint

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
Expand Down
25 changes: 25 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
linters:
auto-fix: false
enable:
- errcheck
- goimports
- golint
- gosec
- misspell
- scopelint
- unconvert
- unparam
- interfacer
- nakedret
- gocyclo
- dupl
- goconst
- lll
run:
linters-settings:
errcheck:
check-type-assertions: true
lll:
line-length: 250
dupl:
threshold: 400
11 changes: 10 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
.PHONY: all build
.PHONY: all build lint
all: build

build:
go build -o bin/kubectl-operator

install: build
install bin/kubectl-operator $(shell go env GOPATH)/bin

GOLANGCI_LINT_VER = "1.29.0"
lint:
# scripts/golangci-lint-check.sh
ifneq (${GOLANGCI_LINT_VER}, "$(shell ./bin/golangci-lint --version 2>/dev/null | cut -b 27-32)")
@echo "golangci-lint missing or not version '${GOLANGCI_LINT_VER}', downloading..."
curl -sSfL "https://raw.githubusercontent.com/golangci/golangci-lint/v${GOLANGCI_LINT_VER}/install.sh" | sh -s -- -b ./bin "v${GOLANGCI_LINT_VER}"
endif
./bin/golangci-lint --timeout 3m run
2 changes: 1 addition & 1 deletion internal/cmd/catalog_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func newCatalogListCmd(cfg *action.Configuration) *cobra.Command {
if allNamespaces {
ns = "\t" + cs.Namespace
}
age := time.Now().Sub(cs.CreationTimestamp.Time)
age := time.Since(cs.CreationTimestamp.Time)
_, _ = 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))
}
_ = tw.Flush()
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/operator_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func newOperatorListCmd(cfg *action.Configuration) *cobra.Command {
if allNamespaces {
ns = "\t" + sub.Namespace
}
age := time.Now().Sub(sub.CreationTimestamp.Time)
age := time.Since(sub.CreationTimestamp.Time)
_, _ = 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))
}
_ = tw.Flush()
Expand Down
2 changes: 1 addition & 1 deletion internal/cmd/operator_list_available.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func newOperatorListAvailableCmd(cfg *action.Configuration) *cobra.Command {
tw := tabwriter.NewWriter(os.Stdout, 3, 4, 2, ' ', 0)
_, _ = fmt.Fprintf(tw, "NAME\tCATALOG\tCHANNEL\tLATEST CSV\tAGE\n")
for _, op := range operators {
age := time.Now().Sub(op.CreationTimestamp.Time)
age := time.Since(op.CreationTimestamp.Time)
for _, ch := range op.Status.Channels {
_, _ = 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))
}
Expand Down
8 changes: 6 additions & 2 deletions internal/pkg/action/operator_install.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ func (i *OperatorInstall) BindFlags(fs *pflag.FlagSet) {
fs.BoolVarP(&i.CreateOperatorGroup, "create-operator-group", "C", false, "create operator group if necessary")

fs.VarP(&i.InstallMode, "install-mode", "i", "install mode")
fs.MarkHidden("install-mode")
err := fs.MarkHidden("install-mode")
if err != nil {
panic(`requested flag "install-mode" missing`)
}
}

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

const (
operatorNameRegexp = `[a-z0-9]([-a-z0-9]*[a-z0-9])?`
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-]+)*))?`
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
)

var csvNameRegexp = regexp.MustCompile(`^(` + operatorNameRegexp + `).(v?)(` + semverRegexp + `)$`)
Expand Down
2 changes: 2 additions & 0 deletions internal/pkg/action/operator_uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func (u *OperatorUninstall) Run(ctx context.Context) error {

var sub *v1alpha1.Subscription
for _, s := range subs.Items {
s := s
if u.Package == s.Spec.Package {
sub = &s
break
Expand Down Expand Up @@ -85,6 +86,7 @@ func (u *OperatorUninstall) Run(ctx context.Context) error {
return fmt.Errorf("list operatorgroups: %v", err)
}
for _, og := range ogs.Items {
og := og
if err := u.config.Client.Delete(ctx, &og); err != nil {
return fmt.Errorf("delete operatorgroup %q: %v", og.Name, err)
}
Expand Down
1 change: 1 addition & 0 deletions internal/pkg/action/operator_upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func (u *OperatorUpgrade) Run(ctx context.Context) (*v1alpha1.ClusterServiceVers

var sub *v1alpha1.Subscription
for _, s := range subs.Items {
s := s
if u.Package == s.Spec.Package {
sub = &s
break
Expand Down