Skip to content

Commit 4376978

Browse files
authored
fix(ci): address linter issues (#163)
1 parent 6c73b41 commit 4376978

File tree

6 files changed

+73
-60
lines changed

6 files changed

+73
-60
lines changed

.golangci.yml

+62-48
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
88
# outputs it results from the linters it executes.
99
output:
1010
# colored-line-number|line-number|json|tab|checkstyle|code-climate, default is "colored-line-number"
11-
format: colored-line-number
11+
formats:
12+
- format: json
13+
path: stderr
14+
- format: colored-line-number
1215

1316
# print lines of code with issue, default is true
1417
print-issued-lines: true
@@ -32,6 +35,18 @@ linters-settings:
3235
lines: 160
3336
statements: 70
3437

38+
# https://github.com/daixiang0/gci
39+
# ensure import order is consistent
40+
# gci write --custom-order -s standard -s default -s blank -s dot -s "prefix(github.com/go-vela)" .
41+
gci:
42+
custom-order: true
43+
sections:
44+
- standard
45+
- default
46+
- blank
47+
- dot
48+
- prefix(github.com/go-vela)
49+
3550
# https://github.com/denis-tingaikin/go-header
3651
goheader:
3752
template: |-
@@ -43,9 +58,9 @@ linters-settings:
4358

4459
# https://github.com/golangci/golangci-lint/blob/master/pkg/golinters/nolintlint
4560
nolintlint:
46-
allow-unused: false # allow nolint directives that don't address a linting issue
47-
require-explanation: true # require an explanation for nolint directives
48-
require-specific: true # require nolint directives to be specific about which linter is being skipped
61+
allow-unused: false # allow nolint directives that don't address a linting issue
62+
require-explanation: true # require an explanation for nolint directives
63+
require-specific: true # require nolint directives to be specific about which linter is being skipped
4964

5065
# This section provides the configuration for which linters
5166
# golangci will execute. Several of them were disabled by
@@ -56,46 +71,43 @@ linters:
5671

5772
# enable a specific set of linters to run
5873
enable:
59-
- bidichk # checks for dangerous unicode character sequences
60-
- bodyclose # checks whether HTTP response body is closed successfully
61-
- contextcheck # check the function whether use a non-inherited context
62-
- deadcode # finds unused code
63-
- dupl # code clone detection
64-
- errcheck # checks for unchecked errors
65-
- errorlint # find misuses of errors
66-
- exportloopref # check for exported loop vars
67-
- funlen # detects long functions
68-
- goconst # finds repeated strings that could be replaced by a constant
69-
- gocyclo # computes and checks the cyclomatic complexity of functions
70-
- godot # checks if comments end in a period
71-
- gofmt # checks whether code was gofmt-ed
72-
- goheader # checks is file header matches to pattern
73-
- goimports # fixes imports and formats code in same style as gofmt
74-
- gomoddirectives # manage the use of 'replace', 'retract', and 'excludes' directives in go.mod
75-
- goprintffuncname # checks that printf-like functions are named with f at the end
76-
- gosec # inspects code for security problems
77-
- gosimple # linter that specializes in simplifying a code
78-
- govet # reports suspicious constructs, ex. Printf calls whose arguments don't align with the format string
79-
- ineffassign # detects when assignments to existing variables aren't used
80-
- makezero # finds slice declarations with non-zero initial length
81-
- misspell # finds commonly misspelled English words in comments
82-
- nakedret # finds naked returns in functions greater than a specified function length
83-
- nilerr # finds the code that returns nil even if it checks that the error is not nil
84-
- noctx # noctx finds sending http request without context.Context
85-
- nolintlint # reports ill-formed or insufficient nolint directives
86-
- revive # linter for go
87-
- staticcheck # applies static analysis checks, go vet on steroids
88-
- structcheck # finds unused struct fields
89-
- stylecheck # replacement for golint
90-
- tenv # analyzer that detects using os.Setenv instead of t.Setenv since Go1.17
91-
- typecheck # parses and type-checks go code, like the front-end of a go compiler
92-
- unconvert # remove unnecessary type conversions
93-
- unparam # reports unused function parameters
94-
- unused # checks for unused constants, variables, functions and types
95-
- varcheck # finds unused global variables and constants
96-
- whitespace # detects leading and trailing whitespace
97-
- wsl # forces code to use empty lines
98-
74+
- bidichk # checks for dangerous unicode character sequences
75+
- bodyclose # checks whether HTTP response body is closed successfully
76+
- contextcheck # check the function whether use a non-inherited context
77+
- dupl # code clone detection
78+
- errcheck # checks for unchecked errors
79+
- errorlint # find misuses of errors
80+
- exportloopref # check for exported loop vars
81+
- funlen # detects long functions
82+
- gci # consistent import ordering
83+
- goconst # finds repeated strings that could be replaced by a constant
84+
- gocyclo # computes and checks the cyclomatic complexity of functions
85+
- godot # checks if comments end in a period
86+
- gofmt # checks whether code was gofmt-ed
87+
- goheader # checks is file header matches to pattern
88+
- gomoddirectives # manage the use of 'replace', 'retract', and 'excludes' directives in go.mod
89+
- goprintffuncname # checks that printf-like functions are named with f at the end
90+
- gosec # inspects code for security problems
91+
- gosimple # linter that specializes in simplifying a code
92+
- govet # reports suspicious constructs, ex. Printf calls whose arguments don't align with the format string
93+
- ineffassign # detects when assignments to existing variables aren't used
94+
- makezero # finds slice declarations with non-zero initial length
95+
- misspell # finds commonly misspelled English words in comments
96+
- nakedret # finds naked returns in functions greater than a specified function length
97+
- nilerr # finds the code that returns nil even if it checks that the error is not nil
98+
- noctx # noctx finds sending http request without context.Context
99+
- nolintlint # reports ill-formed or insufficient nolint directives
100+
- revive # linter for go
101+
- staticcheck # applies static analysis checks, go vet on steroids
102+
- stylecheck # replacement for golint
103+
- tenv # analyzer that detects using os.Setenv instead of t.Setenv since Go1.17
104+
- typecheck # parses and type-checks go code, like the front-end of a go compiler
105+
- unconvert # remove unnecessary type conversions
106+
- unparam # reports unused function parameters
107+
- unused # checks for unused constants, variables, functions and types
108+
- whitespace # detects leading and trailing whitespace
109+
- wsl # forces code to use empty lines
110+
99111
# static list of linters we know golangci can run but we've
100112
# chosen to leave disabled for now
101113
# - asciicheck - non-critical
@@ -108,21 +120,21 @@ linters:
108120
# - exhaustivestruct - style preference
109121
# - forbidigo - unused
110122
# - forcetypeassert - unused
111-
# - gci - use goimports
112123
# - gochecknoinits - unused
113124
# - gochecknoglobals - global variables allowed
114-
# - gocognit - unused complexity metric
125+
# - gocognit - unused complexity metric
115126
# - gocritic - style preference
116127
# - godox - to be used in the future
117128
# - goerr113 - to be used in the future
129+
# - goimports - use gci
118130
# - golint - archived, replaced with revive
119131
# - gofumpt - use gofmt
120132
# - gomnd - get too many false-positives
121133
# - gomodguard - unused
122134
# - ifshort - use both styles
123135
# - ireturn - allow interfaces to be returned
124136
# - importas - want flexibility with naming
125-
# - lll - not too concerned about line length
137+
# - lll - not too concerned about line length
126138
# - interfacer - archived
127139
# - nestif - non-critical
128140
# - nilnil - style preference
@@ -131,7 +143,7 @@ linters:
131143
# - paralleltest - false-positives
132144
# - prealloc - don't use
133145
# - predeclared - unused
134-
# - promlinter - style preference
146+
# - promlinter - style preference
135147
# - rowserrcheck - unused
136148
# - scopelint - deprecated - replaced with exportloopref
137149
# - sqlclosecheck - unused
@@ -154,3 +166,5 @@ issues:
154166
- funlen
155167
- goconst
156168
- gocyclo
169+
- wsl
170+

cmd/vela-s3-cache/main.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ import (
88
"os"
99
"time"
1010

11-
"github.com/go-vela/vela-s3-cache/version"
1211
"github.com/sirupsen/logrus"
1312
"github.com/urfave/cli/v2"
1413

1514
_ "github.com/joho/godotenv/autoload"
15+
16+
"github.com/go-vela/vela-s3-cache/version"
1617
)
1718

1819
//nolint:funlen // ignore function length due to comments and flags
@@ -53,7 +54,6 @@ func main() {
5354

5455
// Plugin Flags
5556
app.Flags = []cli.Flag{
56-
5757
&cli.StringFlag{
5858
EnvVars: []string{"PARAMETER_LOG_LEVEL", "S3_CACHE_LOG_LEVEL"},
5959
FilePath: "/vela/parameters/s3-cache/log_level,/vela/secrets/s3-cache/log_level",

cmd/vela-s3-cache/plugin.go

+3-5
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,9 @@ import (
1010
"github.com/sirupsen/logrus"
1111
)
1212

13-
var (
14-
// ErrInvalidAction defines the error type when the
15-
// Action provided to the Plugin is unsupported.
16-
ErrInvalidAction = errors.New("invalid action provided")
17-
)
13+
// ErrInvalidAction defines the error type when the
14+
// Action provided to the Plugin is unsupported.
15+
var ErrInvalidAction = errors.New("invalid action provided")
1816

1917
// Plugin represents the required information for structs.
2018
type Plugin struct {

cmd/vela-s3-cache/rebuild.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ import (
1010
"time"
1111

1212
"github.com/dustin/go-humanize"
13-
"github.com/go-vela/archiver/v3"
1413
"github.com/minio/minio-go/v7"
1514
"github.com/sirupsen/logrus"
15+
16+
"github.com/go-vela/archiver/v3"
1617
)
1718

1819
const rebuildAction = "rebuild"

cmd/vela-s3-cache/restore.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ import (
99
"time"
1010

1111
"github.com/dustin/go-humanize"
12-
"github.com/go-vela/archiver/v3"
1312
"github.com/minio/minio-go/v7"
1413
"github.com/sirupsen/logrus"
14+
15+
"github.com/go-vela/archiver/v3"
1516
)
1617

1718
const restoreAction = "restore"

version/version.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,10 @@ import (
66
"fmt"
77
"runtime"
88

9-
"github.com/go-vela/types/version"
10-
119
"github.com/Masterminds/semver/v3"
12-
1310
"github.com/sirupsen/logrus"
11+
12+
"github.com/go-vela/types/version"
1413
)
1514

1615
var (

0 commit comments

Comments
 (0)