Skip to content

Commit

Permalink
Merge pull request #1 from kvanzuijlen/add-linting
Browse files Browse the repository at this point in the history
chore: Added golint
  • Loading branch information
kvanzuijlen authored Jan 8, 2024
2 parents 39106f0 + 28ffba0 commit 83c433b
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 19 deletions.
40 changes: 40 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
run:
deadline: 120s
linters:
enable:
- govet
- ineffassign
- goconst
- gofmt
- goimports
- gosec
- gosimple
- staticcheck
- typecheck
- unused
- bodyclose
- dogsled
- goprintffuncname
- misspell
- prealloc
- exportloopref
- stylecheck
- unconvert
- gocritic
- revive
disable-all: true
issues:
exclude-rules:
- path: _test\.go
linters:
- scopelint
- bodyclose
- unconvert
- gocritic
- gosec
# If we have tests in shared test folders, these can be less strictly linted
- path: tests/.*_tests\.go
linters:
- revive
- bodyclose
- stylecheck
23 changes: 23 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
GO ?= go
GOLANGCILINT ?= golangci-lint

GO_MAJOR_VERSION = $(shell $(GO) version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f1)
GO_MINOR_VERSION = $(shell $(GO) version | cut -c 14- | cut -d' ' -f1 | cut -d'.' -f2)
MINIMUM_SUPPORTED_GO_MAJOR_VERSION = 1
MINIMUM_SUPPORTED_GO_MINOR_VERSION = 19

.PHONY: lint
lint: validate-go-version
GO111MODULE=on $(GOLANGCILINT) run

.PHONY: validate-go-version
validate-go-version:
@if [ $(GO_MAJOR_VERSION) -gt $(MINIMUM_SUPPORTED_GO_MAJOR_VERSION) ]; then \
exit 0 ;\
elif [ $(GO_MAJOR_VERSION) -lt $(MINIMUM_SUPPORTED_GO_MAJOR_VERSION) ]; then \
echo '$(GO_VERSION_VALIDATION_ERR_MSG)';\
exit 1; \
elif [ $(GO_MINOR_VERSION) -lt $(MINIMUM_SUPPORTED_GO_MINOR_VERSION) ] ; then \
echo '$(GO_VERSION_VALIDATION_ERR_MSG)';\
exit 1; \
fi
3 changes: 2 additions & 1 deletion cmd/bump.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ package cmd

import (
"fmt"
"needs-a-name/pkg/versioning/semver"

"github.com/spf13/cobra"
"go.uber.org/zap"
"needs-a-name/pkg/versioning/semver"
)

var bumpCmd = &cobra.Command{
Expand Down
3 changes: 2 additions & 1 deletion cmd/latest.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ package cmd

import (
"fmt"
"github.com/spf13/cobra"
"needs-a-name/pkg/datasource"
"needs-a-name/pkg/versioning/semver"

"github.com/spf13/cobra"
)

var (
Expand Down
10 changes: 4 additions & 6 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ Copyright © 2024 Koen van Zuijlen <[email protected]
package cmd

import (
"go.uber.org/zap"
"os"

"go.uber.org/zap"

"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -40,18 +41,15 @@ func init() {
}

func setVersionLevel(_ *cobra.Command, _ []string) {
switch true {
switch {
case major:
versionLevel = "major"
break
case minor:
versionLevel = "minor"
break
case patch:
versionLevel = "patch"
break
default:
versionLevel = "minor"
versionLevel = "patch"
}

zap.L().Debug("Starting...",
Expand Down
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ Copyright © 2024 Koen van Zuijlen <[email protected]
package main

import (
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"needs-a-name/cmd"
"os"

"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)

func createLogger() *zap.Logger {
//return zap.Must(config.Build())
config := zap.NewProductionConfig()
if os.Getenv("LOG_LEVEL") == "debug" {
config = zap.NewDevelopmentConfig()
Expand Down
3 changes: 1 addition & 2 deletions pkg/datasource/datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ type Datasource struct {
}

func Get(datasource string) (IDatasource, error) {
switch datasource {
case "docker":
if datasource == "docker" {
return &Docker{}, nil
}
return nil, errors.New("datasource not found")
Expand Down
1 change: 1 addition & 0 deletions pkg/datasource/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package datasource

import (
"fmt"

"github.com/google/go-containerregistry/pkg/name"
v1 "github.com/google/go-containerregistry/pkg/v1"
"github.com/google/go-containerregistry/pkg/v1/remote"
Expand Down
12 changes: 8 additions & 4 deletions pkg/versioning/semver/bump.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@ Copyright © 2024 Koen van Zuijlen <[email protected]
*/
package semver

import "github.com/coreos/go-semver/semver"
import (
"github.com/coreos/go-semver/semver"
"go.uber.org/zap"
)

func Bump(versionNumber string, versionLevel string, numberOfVersions int) (version *semver.Version, err error) {
version, err = parse(versionNumber)
if err != nil {
zap.L().Error("Error while parsing version", zap.String("versionNumber", versionNumber))
return nil, err
}
for i := 0; i < numberOfVersions; i++ {
version = bumpVersion(versionLevel, version)
}
Expand All @@ -17,13 +24,10 @@ func bumpVersion(versionLevel string, version *semver.Version) *semver.Version {
switch versionLevel {
case "major":
version.BumpMajor()
break
case "minor":
version.BumpMinor()
break
case "patch":
version.BumpPatch()
break
}
return version
}
3 changes: 2 additions & 1 deletion pkg/versioning/semver/select.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ package semver

import (
"fmt"
"slices"

"github.com/coreos/go-semver/semver"
"go.uber.org/zap"
"slices"
)

func Select(tags []string, numberOfVersions int, versionLevel string) (selectedVersions []*semver.Version) {
Expand Down
3 changes: 2 additions & 1 deletion pkg/versioning/semver/sort.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ Copyright © 2024 Koen van Zuijlen <[email protected]
package semver

import (
"github.com/coreos/go-semver/semver"
"sort"

"github.com/coreos/go-semver/semver"
)

func semverSort(list []string) (versions semver.Versions) {
Expand Down

0 comments on commit 83c433b

Please sign in to comment.