Skip to content

Commit

Permalink
chore: pin go version; import order; linter setup (#548)
Browse files Browse the repository at this point in the history
  • Loading branch information
wass3rw3rk authored Apr 11, 2024
1 parent c24173e commit 17a269b
Show file tree
Hide file tree
Showing 233 changed files with 519 additions and 580 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,7 @@ jobs:
# Check that go fmt ./... produces a zero diff; clean up any changes afterwards.
go fmt ./... && git diff --exit-code; code=$?; git checkout -- .; (exit $code)
# Check that go fix ./... produces a zero diff; clean up any changes afterwards.
go fix ./... && git diff --exit-code; code=$?; git checkout -- .; (exit $code)
#
# Renable this after https://github.com/golang/go/commit/7fd62ba821b1044e8e4077df052b0a1232672d57
# has been released.
# go fix ./... && git diff --exit-code; code=$?; git checkout -- .; (exit $code)
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 @@ -290,3 +290,24 @@ bump-deps-full: check
@echo
@echo "### Upgrading all dependencies"
@go get -t -u ./...

# 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
5 changes: 2 additions & 3 deletions action/build/approve.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ package build
import (
"fmt"

"github.com/go-vela/cli/internal/output"
"github.com/sirupsen/logrus"

"github.com/go-vela/cli/internal/output"
"github.com/go-vela/sdk-go/vela"

"github.com/sirupsen/logrus"
)

// Approve approves a build based off the provided configuration.
Expand Down
3 changes: 1 addition & 2 deletions action/build/approve_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import (
"net/http/httptest"
"testing"

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

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

func TestBuild_Config_Approve(t *testing.T) {
Expand Down
5 changes: 2 additions & 3 deletions action/build/cancel.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
package build

import (
"github.com/go-vela/cli/internal/output"
"github.com/sirupsen/logrus"

"github.com/go-vela/cli/internal/output"
"github.com/go-vela/sdk-go/vela"

"github.com/sirupsen/logrus"
)

// Cancel cancels a build based off the provided configuration.
Expand Down
3 changes: 1 addition & 2 deletions action/build/cancel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import (
"net/http/httptest"
"testing"

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

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

func TestBuild_Config_Cancel(t *testing.T) {
Expand Down
5 changes: 2 additions & 3 deletions action/build/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
package build

import (
"github.com/go-vela/cli/internal/output"
"github.com/sirupsen/logrus"

"github.com/go-vela/cli/internal/output"
"github.com/go-vela/sdk-go/vela"

"github.com/sirupsen/logrus"
)

// Get captures a list of builds based off the provided configuration.
Expand Down
3 changes: 1 addition & 2 deletions action/build/get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import (
"net/http/httptest"
"testing"

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

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

func TestBuild_Config_Get(t *testing.T) {
Expand Down
5 changes: 2 additions & 3 deletions action/build/restart.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
package build

import (
"github.com/go-vela/cli/internal/output"
"github.com/sirupsen/logrus"

"github.com/go-vela/cli/internal/output"
"github.com/go-vela/sdk-go/vela"

"github.com/sirupsen/logrus"
)

// Restart restarts a build based off the provided configuration.
Expand Down
3 changes: 1 addition & 2 deletions action/build/restart_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import (
"net/http/httptest"
"testing"

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

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

func TestBuild_Config_Restart(t *testing.T) {
Expand Down
5 changes: 3 additions & 2 deletions action/build/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ import (
"time"

"github.com/dustin/go-humanize"
"github.com/go-vela/cli/internal/output"
"github.com/go-vela/types/library"
"github.com/gosuri/uitable"
"github.com/sirupsen/logrus"

"github.com/go-vela/cli/internal/output"
"github.com/go-vela/types/library"
)

// table is a helper function to output the
Expand Down
5 changes: 2 additions & 3 deletions action/build/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
package build

import (
"github.com/go-vela/cli/internal/output"
"github.com/sirupsen/logrus"

"github.com/go-vela/cli/internal/output"
"github.com/go-vela/sdk-go/vela"

"github.com/sirupsen/logrus"
)

// View inspects a build based off the provided configuration.
Expand Down
3 changes: 1 addition & 2 deletions action/build/view_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@ import (
"net/http/httptest"
"testing"

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

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

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

"github.com/go-vela/cli/internal/output"

"github.com/sirupsen/logrus"

"github.com/go-vela/cli/internal/output"
)

// Generate produces a script used to enable
Expand Down
4 changes: 1 addition & 3 deletions action/config/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ package config
import (
"path/filepath"

"github.com/sirupsen/logrus"
"github.com/spf13/afero"

yaml "gopkg.in/yaml.v3"

"github.com/sirupsen/logrus"
)

// create filesystem based on the operating system
Expand Down
7 changes: 2 additions & 5 deletions action/config/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@ package config
import (
"strings"

"github.com/go-vela/cli/internal"

"github.com/sirupsen/logrus"

"github.com/spf13/afero"

"github.com/urfave/cli/v2"

yaml "gopkg.in/yaml.v3"

"github.com/go-vela/cli/internal"
)

// Load reads the config file and sets the values based off the provided configuration.
Expand Down
4 changes: 2 additions & 2 deletions action/config/load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import (
"flag"
"testing"

"github.com/go-vela/cli/test"
"github.com/spf13/afero"

"github.com/urfave/cli/v2"

"github.com/go-vela/cli/test"
)

func TestConfig_Config_Load(t *testing.T) {
Expand Down
6 changes: 2 additions & 4 deletions action/config/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ package config
import (
"strings"

"github.com/go-vela/cli/internal"

"github.com/sirupsen/logrus"
"github.com/spf13/afero"

yaml "gopkg.in/yaml.v3"

"github.com/sirupsen/logrus"
"github.com/go-vela/cli/internal"
)

// Remove deletes one or more fields from the config file based off the provided configuration.
Expand Down
6 changes: 2 additions & 4 deletions action/config/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@ package config
import (
"strings"

"github.com/go-vela/cli/internal"

"github.com/sirupsen/logrus"
"github.com/spf13/afero"

yaml "gopkg.in/yaml.v3"

"github.com/sirupsen/logrus"
"github.com/go-vela/cli/internal"
)

// Update modifies one or more fields from the config file based off the provided configuration.
Expand Down
5 changes: 2 additions & 3 deletions action/config/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
package config

import (
"github.com/go-vela/cli/internal/output"

"github.com/sirupsen/logrus"
"github.com/spf13/afero"

"github.com/sirupsen/logrus"
"github.com/go-vela/cli/internal/output"
)

// View inspects the config file based off the provided configuration.
Expand Down
Loading

0 comments on commit 17a269b

Please sign in to comment.