Skip to content

Commit

Permalink
Merge pull request #34 from thisissoon/feature/ci-linter-improvements
Browse files Browse the repository at this point in the history
Feature/ci linter improvements
  • Loading branch information
jamesjwarren committed May 31, 2022
2 parents ec2b173 + 687a924 commit 7fc8cf2
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 26 deletions.
3 changes: 2 additions & 1 deletion cookiecutter.json
Expand Up @@ -4,6 +4,7 @@
"origin": null,
"image": "n",
"use_ci": ["gitlab", "circleci", "none"],
"go": "1.11.1",
"go": "1.17.10",
"golangcilint_version": "v1.45.0",
"module": "{{ cookiecutter.origin }}"
}
29 changes: 22 additions & 7 deletions {{cookiecutter.name}}/.golangci.yml
Expand Up @@ -5,23 +5,31 @@ linters:
enable:
- megacheck
- godox
- interfacer
- goconst
- whitespace
- stylecheck
- golint
- revive
- misspell
- depguard
disable:
- scopelint
- maligned
- gci
presets:
- bugs # bodyclose, errcheck, gosec, govet, rowserrcheck, scopelint, staticcheck, typecheck
- complexity # gocognit, gocyclo, nakedret
- format # gofmt, goimports
- performance # bodyclose, maligned, prealloc, rowserrcheck
- unused # deadcode, ineffassign, structcheck, unparam, unused, varcheck
- bugs # asciicheck, bidichk, bodyclose, contextcheck, durationcheck, errcheck, errchkjson, errorlint, exhaustive, exportloopref, gosec, govet, makezero, nilerr, noctx, rowserrcheck, scopelint, sqlclosecheck, staticcheck, typecheck
- complexity # cyclop, funlen, gocognit, gocyclo, maintidx, nestif
- format # decorder, gci, gofmt, gofumpt, goimports
- performance # bodyclose, maligned, noctx, prealloc
- unused # deadcode, ineffassign, structcheck, unparam, unused, varcheck
fast: false

# configuration for specific linters
linters-settings:
funlen:
lines: 80
cyclop:
max-complexity: 12
skip-tests: true
nakedret:
max-func-lines: 0 # no naked returns
goimports:
Expand All @@ -35,3 +43,10 @@ linters-settings:
- github.com/satori/go.uuid
packages-with-error-message:
- github.com/satori/go.uuid: "Unsafe package, prefer github.com/gofrs/uuid"

issues:
exclude-rules:
- path: '(.+)_test\.go'
linters:
- funlen
- gocyclo
9 changes: 3 additions & 6 deletions {{cookiecutter.name}}/build/ci/.gitlab-ci.yml
Expand Up @@ -36,14 +36,11 @@ test:
# Runs code linting
lint:
stage: test
image: golang:{{cookiecutter.go}}-alpine
variables:
GOLANGCILINT_VERSION: v1.21.0
GOLANGCILINT_VERSION: {{cookiecutter.golangcilint_version}}
image: golangci/golangci-lint:${GOLANGCILINT_VERSION}-alpine
script:
- apk update && apk add build-base git
- go mod download
- wget -O - -q https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | sh -s ${GOLANGCILINT_VERSION}
- ./bin/golangci-lint run
- golangci-lint run -c ../.golangci.yml

# Runs dependency vetting
# https://github.com/sonatype-nexus-community/nancy
Expand Down
11 changes: 5 additions & 6 deletions {{cookiecutter.name}}/cmd/{{cookiecutter.name}}/main.go
Expand Up @@ -4,13 +4,12 @@ import (
"io"
"os"

"{{cookiecutter.module}}/internal/config"
"{{cookiecutter.module}}/internal/version"

"github.com/rs/zerolog"
"github.com/spf13/cobra"

configkit "go.soon.build/kit/config"

"{{cookiecutter.module}}/internal/config"
"{{cookiecutter.module}}/internal/version"
)

// Default logger
Expand All @@ -23,7 +22,7 @@ var cfg config.Config
var defaultLog = config.Log{
Console: false,
Verbose: false,
Level: zerolog.LevelDebugValue,
Level: zerolog.DebugLevel.String(),
}

// Application entry point
Expand Down Expand Up @@ -60,7 +59,7 @@ func {{cookiecutter.name|replace('-', '')|replace('.', '')}}Cmd() *cobra.Command
log = initLogger(cfg.Log)
return nil
},
RunE: {{cookiecutter.name|replace('-', '')|replace('.', '')}}Run,
RunE: {{cookiecutter.name|replace('-', '')|replace('.', '')}}Run,
}
// Global flags
pflags := cmd.PersistentFlags()
Expand Down
4 changes: 2 additions & 2 deletions {{cookiecutter.name}}/cmd/{{cookiecutter.name}}/version.go
Expand Up @@ -3,9 +3,9 @@ package main
import (
"os"

"{{cookiecutter.module}}/internal/version"

"github.com/spf13/cobra"

"{{cookiecutter.module}}/internal/version"
)

// versionCmd returns a CLI command that when run prints
Expand Down
2 changes: 1 addition & 1 deletion {{cookiecutter.name}}/go.mod
Expand Up @@ -3,5 +3,5 @@ module {{cookiecutter.module}}
require (
github.com/rs/zerolog v1.11.0
github.com/spf13/cobra v0.0.3
go.soon.build/kit/config v0.0.0-20190802105545-9c7d0e7ffbef
go.soon.build/kit/config v0.0.0-20210812141405-28d18278434a
)
11 changes: 8 additions & 3 deletions {{cookiecutter.name}}/go.sum
Expand Up @@ -14,6 +14,7 @@ github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc
github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk=
github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
Expand Down Expand Up @@ -92,16 +93,18 @@ github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/viper v1.4.0 h1:yXHLWeravcrgGyFSyCgdYpXQ9dR9c/WED3pg1RhxqEU=
github.com/spf13/viper v1.4.0/go.mod h1:PTJ7Z/lr49W6bUbkmS1V3by4uWynFiR9p7+dSq/yZzE=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc=
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
github.com/xordataexchange/crypt v0.0.3-0.20170626215501-b2862e3d0a77/go.mod h1:aYKd//L2LvnjZzWKhF00oedf4jCCReLcmhLdhm1A27Q=
go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
go.soon.build/kit/config v0.0.0-20190802105545-9c7d0e7ffbef h1:pdJta9eCPY1ZUY9jYxNE53T9hpOtyTCCF0b/w2kdoEU=
go.soon.build/kit/config v0.0.0-20190802105545-9c7d0e7ffbef/go.mod h1:kHQq9i7WSbye5tTFzQymPLJqgUDx8DfWE8eO8oL5KEc=
go.soon.build/kit/config v0.0.0-20210812141405-28d18278434a h1:yszeUD9KlZ1xjPp2D9H7Oldq5LUvuw0znFPywBSAG3A=
go.soon.build/kit/config v0.0.0-20210812141405-28d18278434a/go.mod h1:bqF4v1NE/Ycy2OwWXg8J8xQ2zFFWALN13HCiC+UwCHU=
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/multierr v1.1.0/go.mod h1:wR5kodmAFQ0UK8QlbwjlSNy0Z68gJhDJUG5sjR94q/0=
go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
Expand Down Expand Up @@ -143,4 +146,6 @@ gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bl
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=

0 comments on commit 7fc8cf2

Please sign in to comment.