Skip to content

Commit

Permalink
chore: import order (#572)
Browse files Browse the repository at this point in the history
  • Loading branch information
wass3rw3rk authored Apr 11, 2024
1 parent e8783c7 commit 34d5b49
Show file tree
Hide file tree
Showing 78 changed files with 211 additions and 185 deletions.
94 changes: 53 additions & 41 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ linters-settings:
lines: 160
statements: 70

# https://github.com/daixiang0/gci
# ensure import order is consistent
# gci write --custom-order -s standard -s default -s blank -s dot -s "prefix(github.com/go-vela)" .
gci:
custom-order: true
sections:
- standard
- default
- blank
- dot
- prefix(github.com/go-vela)

# https://github.com/denis-tingaikin/go-header
goheader:
template: |-
Expand All @@ -57,46 +69,46 @@ linters:

# enable a specific set of linters to run
enable:
- bidichk # checks for dangerous unicode character sequences
- bodyclose # checks whether HTTP response body is closed successfully
- contextcheck # check the function whether use a non-inherited context
- deadcode # finds unused code
- dupl # code clone detection
- errcheck # checks for unchecked errors
- errorlint # find misuses of errors
- exportloopref # check for exported loop vars
- funlen # detects long functions
- goconst # finds repeated strings that could be replaced by a constant
- gocyclo # computes and checks the cyclomatic complexity of functions
- godot # checks if comments end in a period
- gofmt # checks whether code was gofmt-ed
- goheader # checks is file header matches to pattern
- goimports # fixes imports and formats code in same style as gofmt
- gomoddirectives # manage the use of 'replace', 'retract', and 'excludes' directives in go.mod
- goprintffuncname # checks that printf-like functions are named with f at the end
- gosec # inspects code for security problems
- gosimple # linter that specializes in simplifying a code
- govet # reports suspicious constructs, ex. Printf calls whose arguments don't align with the format string
- ineffassign # detects when assignments to existing variables aren't used
- makezero # finds slice declarations with non-zero initial length
- misspell # finds commonly misspelled English words in comments
- nakedret # finds naked returns in functions greater than a specified function length
- nilerr # finds the code that returns nil even if it checks that the error is not nil
- noctx # noctx finds sending http request without context.Context
- nolintlint # reports ill-formed or insufficient nolint directives
- revive # linter for go
- staticcheck # applies static analysis checks, go vet on steroids
- structcheck # finds unused struct fields
- stylecheck # replacement for golint
- tenv # analyzer that detects using os.Setenv instead of t.Setenv since Go1.17
- typecheck # parses and type-checks go code, like the front-end of a go compiler
- unconvert # remove unnecessary type conversions
- unparam # reports unused function parameters
- unused # checks for unused constants, variables, functions and types
- varcheck # finds unused global variables and constants
- whitespace # detects leading and trailing whitespace
- wsl # forces code to use empty lines
- bidichk # checks for dangerous unicode character sequences
- bodyclose # checks whether HTTP response body is closed successfully
- contextcheck # check the function whether use a non-inherited context
- deadcode # finds unused code
- dupl # code clone detection
- errcheck # checks for unchecked errors
- errorlint # find misuses of errors
- exportloopref # check for exported loop vars
- funlen # detects long functions
- gci # consistent import ordering
- goconst # finds repeated strings that could be replaced by a constant
- gocyclo # computes and checks the cyclomatic complexity of functions
- godot # checks if comments end in a period
- gofmt # checks whether code was gofmt-ed
- goheader # checks is file header matches to pattern
- gomoddirectives # manage the use of 'replace', 'retract', and 'excludes' directives in go.mod
- goprintffuncname # checks that printf-like functions are named with f at the end
- gosec # inspects code for security problems
- gosimple # linter that specializes in simplifying a code
- govet # reports suspicious constructs, ex. Printf calls whose arguments don't align with the format string
- ineffassign # detects when assignments to existing variables aren't used
- makezero # finds slice declarations with non-zero initial length
- misspell # finds commonly misspelled English words in comments
- nakedret # finds naked returns in functions greater than a specified function length
- nilerr # finds the code that returns nil even if it checks that the error is not nil
- noctx # noctx finds sending http request without context.Context
- nolintlint # reports ill-formed or insufficient nolint directives
- revive # linter for go
- staticcheck # applies static analysis checks, go vet on steroids
- structcheck # finds unused struct fields
- stylecheck # replacement for golint
- tenv # analyzer that detects using os.Setenv instead of t.Setenv since Go1.17
- typecheck # parses and type-checks go code, like the front-end of a go compiler
- unconvert # remove unnecessary type conversions
- unparam # reports unused function parameters
- unused # checks for unused constants, variables, functions and types
- varcheck # finds unused global variables and constants
- whitespace # detects leading and trailing whitespace
- wsl # forces code to use empty lines

# static list of linters we know golangci can run but we've
# chosen to leave disabled for now
# - asciicheck - non-critical
Expand All @@ -109,13 +121,13 @@ linters:
# - exhaustivestruct - style preference
# - forbidigo - unused
# - forcetypeassert - unused
# - gci - use goimports
# - gochecknoinits - unused
# - gochecknoglobals - global variables allowed
# - gocognit - unused complexity metric
# - gocritic - style preference
# - godox - to be used in the future
# - goerr113 - to be used in the future
# - goimports - use gci
# - golint - archived, replaced with revive
# - gofumpt - use gofmt
# - gomnd - get too many false-positives
Expand Down
21 changes: 21 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,27 @@ spec-version-update:
.PHONY: spec
spec: spec-gen spec-version-update spec-validate

# The `lint` target is intended to lint the
# Go source code with golangci-lint.
#
# Usage: `make lint`
.PHONY: lint
lint:
@echo
@echo "### Linting Go Code"
@golangci-lint run ./...

# The `lintfix` target is intended to lint the
# Go source code with golangci-lint and apply
# any fixes that can be automatically applied.
#
# Usage: `make lintfix`
.PHONY: lintfix
lintfix:
@echo
@echo "### Fixing Go code with linter"
@golangci-lint run ./... --fix

# The `crd-gen` target is intended to create a k8s CRD client
# for the kubernetes runtime using k8s.io/code-generator
#
Expand Down
4 changes: 2 additions & 2 deletions api/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"fmt"
"net/http"

"github.com/go-vela/types"

"github.com/gin-gonic/gin"

"github.com/go-vela/types"
"github.com/go-vela/worker/router/middleware/executor"
)

Expand Down
4 changes: 2 additions & 2 deletions api/pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"fmt"
"net/http"

"github.com/go-vela/types"

"github.com/gin-gonic/gin"

"github.com/go-vela/types"
"github.com/go-vela/worker/router/middleware/executor"
)

Expand Down
3 changes: 2 additions & 1 deletion api/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import (
"net/http"

"github.com/gin-gonic/gin"
"github.com/go-vela/worker/router/middleware/token"
"github.com/golang-jwt/jwt/v5"

"github.com/go-vela/worker/router/middleware/token"
)

// swagger:operation POST /register system Register
Expand Down
4 changes: 2 additions & 2 deletions api/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (
"fmt"
"net/http"

"github.com/go-vela/types"

"github.com/gin-gonic/gin"

"github.com/go-vela/types"
"github.com/go-vela/worker/router/middleware/executor"
)

Expand Down
4 changes: 2 additions & 2 deletions cmd/vela-worker/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
package main

import (
"github.com/go-vela/sdk-go/vela"

"github.com/sirupsen/logrus"

"github.com/go-vela/sdk-go/vela"
)

// helper function to setup the queue from the CLI arguments.
Expand Down
4 changes: 2 additions & 2 deletions cmd/vela-worker/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ package main
import (
"time"

"github.com/urfave/cli/v2"

"github.com/go-vela/server/queue"
"github.com/go-vela/worker/executor"
"github.com/go-vela/worker/runtime"

"github.com/urfave/cli/v2"
)

// flags is a helper function to return the all
Expand Down
5 changes: 2 additions & 3 deletions cmd/vela-worker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ import (
"os"
"time"

"github.com/go-vela/worker/version"

"github.com/sirupsen/logrus"

"github.com/urfave/cli/v2"

_ "github.com/joho/godotenv/autoload"

"github.com/go-vela/worker/version"
)

// hostname stores the worker host name reported by the kernel.
Expand Down
4 changes: 2 additions & 2 deletions cmd/vela-worker/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (
"strings"
"time"

"github.com/sirupsen/logrus"

"github.com/go-vela/worker/router"
"github.com/go-vela/worker/router/middleware"

"github.com/sirupsen/logrus"
)

// server is a helper function to listen and serve
Expand Down
5 changes: 1 addition & 4 deletions executor/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,10 @@ import (

"github.com/gin-gonic/gin"

"github.com/go-vela/sdk-go/vela"
"github.com/go-vela/server/mock/server"

"github.com/go-vela/worker/executor/linux"

"github.com/go-vela/worker/runtime/docker"

"github.com/go-vela/sdk-go/vela"
)

func TestExecutor_FromContext(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ package executor
import (
"fmt"

"github.com/go-vela/types/constants"

"github.com/sirupsen/logrus"

"github.com/go-vela/types/constants"
)

// New creates and returns a Vela engine capable of
Expand Down
12 changes: 4 additions & 8 deletions executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,16 @@ import (
"github.com/gin-gonic/gin"
"github.com/google/go-cmp/cmp"

"github.com/go-vela/sdk-go/vela"
api "github.com/go-vela/server/api/types"
"github.com/go-vela/server/api/types/actions"
"github.com/go-vela/server/mock/server"

"github.com/go-vela/worker/executor/linux"
"github.com/go-vela/worker/executor/local"

"github.com/go-vela/worker/runtime/docker"

"github.com/go-vela/sdk-go/vela"

"github.com/go-vela/types/constants"
"github.com/go-vela/types/library"
"github.com/go-vela/types/pipeline"
"github.com/go-vela/worker/executor/linux"
"github.com/go-vela/worker/executor/local"
"github.com/go-vela/worker/runtime/docker"
)

func TestExecutor_New(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions executor/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ package executor
import (
"time"

"github.com/go-vela/types/constants"

"github.com/urfave/cli/v2"

"github.com/go-vela/types/constants"
)

// Flags represents all supported command line
Expand Down
8 changes: 4 additions & 4 deletions executor/linux/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@ import (
"testing"
"time"

"github.com/gin-gonic/gin"
"github.com/sirupsen/logrus"
logrusTest "github.com/sirupsen/logrus/hooks/test"
"github.com/urfave/cli/v2"
v1 "k8s.io/api/core/v1"

"github.com/gin-gonic/gin"
"github.com/go-vela/sdk-go/vela"
api "github.com/go-vela/server/api/types"
"github.com/go-vela/server/compiler/native"
Expand All @@ -24,9 +27,6 @@ import (
"github.com/go-vela/worker/runtime"
"github.com/go-vela/worker/runtime/docker"
"github.com/go-vela/worker/runtime/kubernetes"
"github.com/sirupsen/logrus"
logrusTest "github.com/sirupsen/logrus/hooks/test"
"github.com/urfave/cli/v2"
)

func TestLinux_CreateBuild(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions executor/linux/driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"testing"

"github.com/gin-gonic/gin"

"github.com/go-vela/sdk-go/vela"
"github.com/go-vela/server/mock/server"
"github.com/go-vela/types/constants"
Expand Down
3 changes: 2 additions & 1 deletion executor/linux/linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ import (
"sync"
"time"

"github.com/sirupsen/logrus"

"github.com/go-vela/sdk-go/vela"
api "github.com/go-vela/server/api/types"
"github.com/go-vela/types/library"
"github.com/go-vela/types/pipeline"
"github.com/go-vela/worker/internal/message"
"github.com/go-vela/worker/runtime"
"github.com/sirupsen/logrus"
)

type (
Expand Down
2 changes: 1 addition & 1 deletion executor/linux/linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import (
"net/http/httptest"
"testing"

"github.com/gin-gonic/gin"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/gin-gonic/gin"
"github.com/go-vela/sdk-go/vela"
api "github.com/go-vela/server/api/types"
"github.com/go-vela/server/mock/server"
Expand Down
3 changes: 2 additions & 1 deletion executor/linux/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import (
"fmt"
"time"

"github.com/sirupsen/logrus"

"github.com/go-vela/sdk-go/vela"
api "github.com/go-vela/server/api/types"
"github.com/go-vela/types/library"
"github.com/go-vela/types/pipeline"
"github.com/go-vela/worker/internal/message"
"github.com/go-vela/worker/runtime"
"github.com/sirupsen/logrus"
)

// Opt represents a configuration option to initialize the executor client for Linux.
Expand Down
Loading

0 comments on commit 34d5b49

Please sign in to comment.