refactor: add more linters and fix findings (#49)

This commit is contained in:
Robert Kaussow 2023-02-08 10:13:55 +01:00 committed by GitHub
parent 870aef309e
commit ddd51bf1c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 113 additions and 38 deletions

View File

@ -8,7 +8,7 @@ platform:
steps: steps:
- name: deps - name: deps
image: golang:1.19 image: golang:1.20
commands: commands:
- make deps - make deps
volumes: volumes:
@ -16,7 +16,7 @@ steps:
path: /go path: /go
- name: lint - name: lint
image: golang:1.19 image: golang:1.20
commands: commands:
- make lint - make lint
volumes: volumes:
@ -24,7 +24,7 @@ steps:
path: /go path: /go
- name: test - name: test
image: golang:1.19 image: golang:1.20
commands: commands:
- make test - make test
volumes: volumes:
@ -59,7 +59,7 @@ platform:
steps: steps:
- name: build - name: build
image: techknowlogick/xgo:go-1.19.x image: techknowlogick/xgo:go-1.20.x
commands: commands:
- ln -s /drone/src /source - ln -s /drone/src /source
- make release - make release
@ -143,6 +143,6 @@ depends_on:
--- ---
kind: signature kind: signature
hmac: e1c222b7a3d1b7aff9c4bea8205334456a620682a4cc4f6bb3959857f5029ebc hmac: 25950586df979c42abe8651c8ee415ff6f8eab3261f4f5ac39c9c686fc43f843
... ...

View File

@ -1,25 +1,92 @@
linters: linters:
enable:
- gosimple
- deadcode
- typecheck
- govet
- errcheck
- staticcheck
- unused
- structcheck
- varcheck
- dupl
- gofmt
- misspell
- gocritic
- bidichk
- ineffassign
- revive
- gofumpt
- depguard
enable-all: false enable-all: false
disable-all: true disable-all: true
enable:
- errcheck
- gosimple
- govet
- ineffassign
- staticcheck
- typecheck
- unused
- asasalint
- asciicheck
- bidichk
- bodyclose
- containedctx
- contextcheck
- decorder
- depguard
- dogsled
- dupl
- dupword
- durationcheck
- errchkjson
- errname
- errorlint
- execinquery
- exhaustive
- exportloopref
- forcetypeassert
- ginkgolinter
- gocheckcompilerdirectives
- gochecknoglobals
- gochecknoinits
- gocognit
- goconst
- gocritic
- gocyclo
- godot
- godox
- goerr113
- gofmt
- gofumpt
- goheader
- goimports
- gomnd
- gomoddirectives
- gomodguard
- goprintffuncname
- gosec
- grouper
- importas
- interfacebloat
- ireturn
- lll
- loggercheck
- maintidx
- makezero
- misspell
- musttag
- nakedret
- nestif
- nilerr
- nilnil
- nlreturn
- noctx
- nolintlint
- nonamedreturns
- nosprintfhostport
- prealloc
- predeclared
- promlinter
- reassign
- revive
# - rowserrcheck
# - sqlclosecheck
# - structcheck
- stylecheck
- tagliatelle
- tenv
- testableexamples
- thelper
- tparallel
- unconvert
- unparam
- usestdlibvars
# - wastedassign
- whitespace
- wsl
fast: false fast: false
run: run:
@ -28,4 +95,4 @@ run:
linters-settings: linters-settings:
gofumpt: gofumpt:
extra-rules: true extra-rules: true
lang-version: "1.18" lang-version: "1.20"

View File

@ -19,7 +19,7 @@ GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/cmd/golangci-lint@$(G
XGO_PACKAGE ?= src.techknowlogick.com/xgo@latest XGO_PACKAGE ?= src.techknowlogick.com/xgo@latest
GENERATE ?= GENERATE ?=
XGO_VERSION := go-1.19.x XGO_VERSION := go-1.20.x
XGO_TARGETS ?= linux/amd64,linux/arm-6,linux/arm-7,linux/arm64 XGO_TARGETS ?= linux/amd64,linux/arm-6,linux/arm-7,linux/arm64
TARGETOS ?= linux TARGETOS ?= linux

View File

@ -9,6 +9,7 @@ import (
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
) )
//nolint:gochecknoglobals
var ( var (
BuildVersion = "devel" BuildVersion = "devel"
BuildDate = "00000000" BuildDate = "00000000"

2
go.mod
View File

@ -1,6 +1,6 @@
module github.com/thegeeklab/url-parser module github.com/thegeeklab/url-parser
go 1.19 go 1.20
require ( require (
github.com/sirupsen/logrus v1.9.0 github.com/sirupsen/logrus v1.9.0

View File

@ -8,6 +8,7 @@ type TestParseData struct {
} }
func TestParseURL(t *testing.T) { func TestParseURL(t *testing.T) {
//nolint:goconst
urlString := "postgres://user:pass@host.com:5432/path/to?key=value&other=other%20value#some-fragment" urlString := "postgres://user:pass@host.com:5432/path/to?key=value&other=other%20value#some-fragment"
tables := []TestParseData{ tables := []TestParseData{

View File

@ -6,12 +6,13 @@ import (
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
) )
// Fragment prints out the fragment part from the url // Fragment prints out the fragment part from the url.
func Fragment(ctx *cli.Context) error { func Fragment(ctx *cli.Context) error {
parts := parseURL(ctx.String("url")) parts := parseURL(ctx.String("url"))
if len(parts.Scheme) > 0 { if len(parts.Scheme) > 0 {
fmt.Println(parts.Fragment) fmt.Println(parts.Fragment)
} }
return nil return nil
} }

View File

@ -6,12 +6,13 @@ import (
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
) )
// Host prints out the host part from the url // Host prints out the host part from the url.
func Host(ctx *cli.Context) error { func Host(ctx *cli.Context) error {
parts := parseURL(ctx.String("url")) parts := parseURL(ctx.String("url"))
if len(parts.Scheme) > 0 { if len(parts.Scheme) > 0 {
fmt.Println(parts.Hostname()) fmt.Println(parts.Hostname())
} }
return nil return nil
} }

View File

@ -6,7 +6,7 @@ import (
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
) )
// Password prints out the password part from url // Password prints out the password part from url.
func Password(ctx *cli.Context) error { func Password(ctx *cli.Context) error {
parts := parseURL(ctx.String("url")) parts := parseURL(ctx.String("url"))

View File

@ -7,7 +7,7 @@ import (
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
) )
// PathFlags defines flags for path subcommand // PathFlags defines flags for path subcommand.
func PathFlags() []cli.Flag { func PathFlags() []cli.Flag {
return []cli.Flag{ return []cli.Flag{
&cli.IntFlag{ &cli.IntFlag{
@ -19,7 +19,7 @@ func PathFlags() []cli.Flag {
} }
} }
// Path prints out the path part from url // Path prints out the path part from url.
func Path(ctx *cli.Context) error { func Path(ctx *cli.Context) error {
parts := parseURL(ctx.String("url")) parts := parseURL(ctx.String("url"))
i := ctx.Int("path-index") i := ctx.Int("path-index")

View File

@ -6,12 +6,13 @@ import (
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
) )
// Port prints out the port from the url // Port prints out the port from the url.
func Port(ctx *cli.Context) error { func Port(ctx *cli.Context) error {
parts := parseURL(ctx.String("url")) parts := parseURL(ctx.String("url"))
if len(parts.Scheme) > 0 { if len(parts.Scheme) > 0 {
fmt.Println(parts.Port()) fmt.Println(parts.Port())
} }
return nil return nil
} }

View File

@ -6,7 +6,7 @@ import (
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
) )
// QueryFlags defines flags for query subcommand // QueryFlags defines flags for query subcommand.
func QueryFlags() []cli.Flag { func QueryFlags() []cli.Flag {
return []cli.Flag{ return []cli.Flag{
&cli.StringFlag{ &cli.StringFlag{
@ -17,7 +17,7 @@ func QueryFlags() []cli.Flag {
} }
} }
// Query prints out the query part from url // Query prints out the query part from url.
func Query(ctx *cli.Context) error { func Query(ctx *cli.Context) error {
parts := parseURL(ctx.String("url")) parts := parseURL(ctx.String("url"))
f := ctx.String("query-field") f := ctx.String("query-field")

View File

@ -6,12 +6,13 @@ import (
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
) )
// Run default command and print out full url // Run default command and print out full url.
func Run(ctx *cli.Context) error { func Run(ctx *cli.Context) error {
parts := parseURL(ctx.String("url")) parts := parseURL(ctx.String("url"))
if len(parts.String()) > 0 { if len(parts.String()) > 0 {
fmt.Println(parts) fmt.Println(parts)
} }
return nil return nil
} }

View File

@ -6,12 +6,13 @@ import (
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
) )
// Scheme prints out the scheme part from the url // Scheme prints out the scheme part from the url.
func Scheme(ctx *cli.Context) error { func Scheme(ctx *cli.Context) error {
parts := parseURL(ctx.String("url")) parts := parseURL(ctx.String("url"))
if len(parts.Scheme) > 0 { if len(parts.Scheme) > 0 {
fmt.Println(parts.Scheme) fmt.Println(parts.Scheme)
} }
return nil return nil
} }

View File

@ -6,7 +6,7 @@ import (
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
) )
// User prints out the user part from url // User prints out the user part from url.
func User(ctx *cli.Context) error { func User(ctx *cli.Context) error {
parts := parseURL(ctx.String("url")) parts := parseURL(ctx.String("url"))
@ -15,5 +15,6 @@ func User(ctx *cli.Context) error {
fmt.Println(parts.User.Username()) fmt.Println(parts.User.Username())
} }
} }
return nil return nil
} }