Skip to content
This repository has been archived by the owner on Aug 29, 2023. It is now read-only.

Commit

Permalink
refactor: add more linters and fix findings (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
xoxys authored Feb 8, 2023
1 parent b00aab9 commit 22ebe21
Show file tree
Hide file tree
Showing 17 changed files with 279 additions and 116 deletions.
10 changes: 5 additions & 5 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@ platform:

steps:
- name: deps
image: golang:1.19
image: golang:1.20
commands:
- make deps
volumes:
- name: godeps
path: /go

- name: lint
image: golang:1.19
image: golang:1.20
commands:
- make lint
volumes:
- name: godeps
path: /go

- name: test
image: golang:1.19
image: golang:1.20
commands:
- make test
volumes:
Expand All @@ -51,7 +51,7 @@ platform:

steps:
- name: build
image: techknowlogick/xgo:go-1.19.x
image: techknowlogick/xgo:go-1.20.x
commands:
- ln -s /drone/src /source
- make release
Expand Down Expand Up @@ -292,6 +292,6 @@ depends_on:

---
kind: signature
hmac: 8b920283ba7cc82bad64ea0eb55b8cf3de5aae95ca0f7018bac9f0deb8b22244
hmac: 89039f09e352a636edf52307e5e48f8bd54f4d9f0b2cf55dabddfdca88702bda

...
93 changes: 80 additions & 13 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,92 @@
linters:
enable-all: false
disable-all: true
enable:
- errcheck
- gosimple
- deadcode
- typecheck
- govet
- errcheck
- ineffassign
- staticcheck
- typecheck
- unused
- structcheck
- varcheck
- 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
- gocritic
- bidichk
- ineffassign
- musttag
- nakedret
- nestif
- nilerr
- nilnil
- nlreturn
- noctx
- nolintlint
- nonamedreturns
- nosprintfhostport
- prealloc
- predeclared
- promlinter
- reassign
- revive
- gofumpt
- depguard
enable-all: false
disable-all: true
# - rowserrcheck
# - sqlclosecheck
# - structcheck
- stylecheck
- tagliatelle
- tenv
- testableexamples
- thelper
- tparallel
- unconvert
- unparam
- usestdlibvars
# - wastedassign
- whitespace
- wsl
fast: false

run:
Expand All @@ -28,4 +95,4 @@ run:
linters-settings:
gofumpt:
extra-rules: true
lang-version: "1.18"
lang-version: "1.20"
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/cmd/golangci-lint@$(G
XGO_PACKAGE ?= src.techknowlogick.com/xgo@latest

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

TARGETOS ?= linux
Expand Down
2 changes: 1 addition & 1 deletion cmd/drone-git-action/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ func settingsFlags(settings *plugin.Settings, category string) []cli.Flag {
return []cli.Flag{
&cli.StringSliceFlag{
Name: "action",
Usage: "git action to to execute",
Usage: "git action to execute",
EnvVars: []string{"PLUGIN_ACTION"},
Destination: &settings.Action,
Required: true,
Expand Down
1 change: 1 addition & 0 deletions cmd/drone-git-action/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/urfave/cli/v2"
)

//nolint:gochecknoglobals
var (
BuildVersion = "devel"
BuildDate = "00000000"
Expand Down
23 changes: 16 additions & 7 deletions git/clone.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,21 @@ package git
import (
"fmt"
"os"
"os/exec"

"golang.org/x/sys/execabs"
)

// FetchSource fetches the source from remote.
func FetchSource(repo Repository) *exec.Cmd {
cmd := exec.Command(
"git",
func FetchSource(repo Repository) *execabs.Cmd {
args := []string{
"fetch",
"origin",
fmt.Sprintf("+%s:", repo.Branch),
}

cmd := execabs.Command(
gitBin,
args...,
)
cmd.Dir = repo.WorkDir
cmd.Stderr = os.Stderr
Expand All @@ -21,12 +26,16 @@ func FetchSource(repo Repository) *exec.Cmd {
}

// CheckoutHead handles branch checkout.
func CheckoutHead(repo Repository) *exec.Cmd {
cmd := exec.Command(
"git",
func CheckoutHead(repo Repository) *execabs.Cmd {
args := []string{
"checkout",
"-qf",
repo.Branch,
}

cmd := execabs.Command(
gitBin,
args...,
)
cmd.Dir = repo.WorkDir
cmd.Stderr = os.Stderr
Expand Down
45 changes: 27 additions & 18 deletions git/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package git

import (
"os"
"os/exec"

"golang.org/x/sys/execabs"
)

// ForceAdd forces the addition of all dirty files.
func ForceAdd(repo Repository) *exec.Cmd {
cmd := exec.Command(
"git",
func ForceAdd(repo Repository) *execabs.Cmd {
cmd := execabs.Command(
gitBin,
"add",
"--all",
"--force",
Expand All @@ -20,9 +21,9 @@ func ForceAdd(repo Repository) *exec.Cmd {
}

// Add updates the index to match the working tree.
func Add(repo Repository) *exec.Cmd {
cmd := exec.Command(
"git",
func Add(repo Repository) *execabs.Cmd {
cmd := execabs.Command(
gitBin,
"add",
)
cmd.Dir = repo.WorkDir
Expand All @@ -37,10 +38,10 @@ func Add(repo Repository) *exec.Cmd {
return cmd
}

// TestCleanTree returns non-zero if diff between index and local repository
func TestCleanTree(repo Repository) *exec.Cmd {
cmd := exec.Command(
"git",
// TestCleanTree returns non-zero if diff between index and local repository.
func TestCleanTree(repo Repository) *execabs.Cmd {
cmd := execabs.Command(
gitBin,
"diff-index",
"--quiet",
"HEAD",
Expand All @@ -52,14 +53,18 @@ func TestCleanTree(repo Repository) *exec.Cmd {
return cmd
}

// EmptyCommit simply create an empty commit
func EmptyCommit(repo Repository) *exec.Cmd {
cmd := exec.Command(
"git",
// EmptyCommit simply create an empty commit.
func EmptyCommit(repo Repository) *execabs.Cmd {
args := []string{
"commit",
"--allow-empty",
"-m",
repo.CommitMsg,
}

cmd := execabs.Command(
gitBin,
args...,
)
cmd.Dir = repo.WorkDir
cmd.Stderr = os.Stderr
Expand All @@ -72,12 +77,16 @@ func EmptyCommit(repo Repository) *exec.Cmd {
}

// ForceCommit commits every change while skipping CI.
func ForceCommit(repo Repository) *exec.Cmd {
cmd := exec.Command(
"git",
func ForceCommit(repo Repository) *execabs.Cmd {
args := []string{
"commit",
"-m",
repo.CommitMsg,
}

cmd := execabs.Command(
gitBin,
args...,
)
cmd.Dir = repo.WorkDir
cmd.Stderr = os.Stderr
Expand Down
Loading

0 comments on commit 22ebe21

Please sign in to comment.