Skip to content

Commit fe3bfb6

Browse files
dekimseymartinbaillie
authored andcommitted
Fix golangci-lint configuration
Addresses the following errors: * Error: can't load config: unsupported version of the configuration: "" * Error: can't load config: typecheck is not a linter, it cannot be enabled or disabled * Error: can't load config: gofmt is a formatter * Error: can't load config: goimports is a formatter * Error: unknown linters: 'gosimple,stylecheck,tenv' Enabling the linter with the existing configs caused it to identify problems in existing code. These failures are either silenced or fixed. I only fixed errors that were minor to correct to avoid any larger refactor to satisfy the linter. ``` 7 issues: * cyclop: 2 * wsl: 2 * errcheck: 3 ``` fixup
1 parent c93a4e9 commit fe3bfb6

File tree

4 files changed

+27
-30
lines changed

4 files changed

+27
-30
lines changed

.golangci.yml

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
11
---
2+
version: 2
23
run:
34
tests: false
5+
formatters:
6+
settings:
7+
gofmt:
8+
# Apply the rewrite rules to the source before reformatting.
9+
# https://pkg.go.dev/cmd/gofmt
10+
# Default: []
11+
rewrite-rules:
12+
- pattern: "interface{}"
13+
replacement: "any"
14+
- pattern: "a[b:len(a)]"
15+
replacement: "a[b:]"
16+
goimports:
17+
# Put imports beginning with prefix after 3rd-party packages.
18+
local-prefixes:
19+
- github.com/martinbaillie
420

521
linters:
622
disable-all: true
@@ -24,12 +40,9 @@ linters:
2440
- gocritic # provides diagnostics that check for bugs, performance and style issues
2541
- gocyclo # computes and checks the cyclomatic complexity of functions
2642
- godot # checks if comments end in a period
27-
- gofmt # the classic
28-
- goimports # in addition to fixing imports, goimports also formats your code in the same style as gofmt
2943
# - gomnd # detects magic numbers
3044
- goprintffuncname # checks that printf-like functions are named with f at the end
3145
- gosec # inspects source code for security problems
32-
- gosimple # specializes in simplifying a code
3346
- govet # reports suspicious constructs, such as Printf calls whose arguments do not align with the format string
3447
- ineffassign # detects when assignments to existing variables are not used
3548
# - ireturn # accept interfaces, return concrete types
@@ -47,13 +60,10 @@ linters:
4760
- reassign # checks that package variables are not reassigned
4861
- revive # fast, configurable, extensible, flexible, and beautiful linter for Go, drop-in replacement of golint
4962
- staticcheck # is a go vet on steroids, applying a ton of static analysis checks
50-
- stylecheck # is a replacement for golint
5163
# - tagliatelle # struct tag issues
52-
- tenv # detects using os.Setenv instead of t.Setenv since Go1.17
5364
- testpackage # makes you use a separate _test package
5465
- thelper # detects golang test helpers without t.Helper() call and checks the consistency of test helpers
5566
- tparallel # detects inappropriate usage of t.Parallel() method in your Go test codes
56-
- typecheck # like the front-end of a Go compiler, parses and type-checks Go code
5767
- unconvert # removes unnecessary type conversions
5868
- unparam # reports unused function parameters
5969
- unused # checks for unused constants, variables, functions and types
@@ -97,10 +107,6 @@ linters-settings:
97107
allow-cuddle-declarations: true
98108
allow-assign-and-anything: true
99109

100-
goimports:
101-
# Put imports beginning with prefix after 3rd-party packages.
102-
local-prefixes: github.com/martinbaillie
103-
104110
gocritic:
105111
# The settings key is the name of a supported gocritic checker. The list of
106112
# supported checkers can be find in https://go-critic.github.io/overview.
@@ -113,16 +119,6 @@ linters-settings:
113119
# Default: true
114120
skipRecvDeref: false
115121

116-
gofmt:
117-
# Apply the rewrite rules to the source before reformatting.
118-
# https://pkg.go.dev/cmd/gofmt
119-
# Default: []
120-
rewrite-rules:
121-
- pattern: "interface{}"
122-
replacement: "any"
123-
- pattern: "a[b:len(a)]"
124-
replacement: "a[b:]"
125-
126122
gomnd:
127123
# Magic numbers. List of function patterns to exclude from analysis. Values
128124
# always ignored: `time.Date` Default: []
@@ -161,7 +157,7 @@ linters-settings:
161157

162158
nolintlint:
163159
# Exclude following linters from requiring an explanation. Default: []
164-
allow-no-explanation: [funlen, gocognit, lll]
160+
allow-no-explanation: [ funlen, gocognit, lll ]
165161
# Enable to require an explanation of nonzero length after each nolint
166162
# directive. Default: false
167163
require-explanation: true

flake.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,9 +160,9 @@
160160
if [ -v CI ]; then
161161
mkdir -p test
162162
${golangci-lint}/bin/golangci-lint run \
163-
--out-format=checkstyle | tee test/checkstyle.xml
163+
--output.checkstyle.path stdout | tee test/checkstyle.xml
164164
else
165-
${golangci-lint}/bin/golangci-lint run --fast
165+
${golangci-lint}/bin/golangci-lint run --fast-only
166166
fi
167167
'';
168168
help = "lint the project (heavyweight when CI=true)";

github/client.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ func (c *Client) Token(ctx context.Context, tokReq *tokenRequest) (*logical.Resp
174174
return c.token(ctx, tokReq)
175175
}
176176

177-
func (c *Client) token(ctx context.Context, tokReq *tokenRequest) (*logical.Response, error) {
177+
func (c *Client) token(ctx context.Context, tokReq *tokenRequest) (*logical.Response, error) { //nolint:cyclop,funlen
178178
accessTokenURL, err := c.accessTokenURLForInstallationID(tokReq.InstallationID)
179179
if err != nil {
180180
return nil, fmt.Errorf("%s: %w", errUnableToBuildAccessTokenURL, err)
@@ -204,7 +204,7 @@ func (c *Client) token(ctx context.Context, tokReq *tokenRequest) (*logical.Resp
204204
return nil, fmt.Errorf("%s: %w", errUnableToCreateAccessToken, err)
205205
}
206206

207-
defer res.Body.Close()
207+
defer res.Body.Close() //nolint:errcheck
208208

209209
if statusCode(res.StatusCode).Unsuccessful() {
210210
var bodyBytes []byte
@@ -239,10 +239,11 @@ func (c *Client) token(ctx context.Context, tokReq *tokenRequest) (*logical.Resp
239239
resData["repositories"] = repoNames
240240
}
241241
}
242-
tokRes := &logical.Response{Data: resData}
243242

244243
// Enrich the response with what we know about the installation.
244+
tokRes := &logical.Response{Data: resData}
245245
tokRes.Data["installation_id"] = tokReq.InstallationID
246+
246247
if tokReq.OrgName != "" {
247248
tokRes.Data["org_name"] = tokReq.OrgName
248249
}
@@ -311,8 +312,8 @@ func (c *Client) installationID(ctx context.Context, orgName string) (int, error
311312
// fetchInstallations makes a request to the GitHub API to fetch the installations.
312313
func (c *Client) fetchInstallations(ctx context.Context) ([]installation, error) {
313314
var allInstallations []installation
314-
url := c.installationsURL.String()
315315

316+
url := c.installationsURL.String()
316317
for url != "" {
317318
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
318319
if err != nil {
@@ -327,7 +328,7 @@ func (c *Client) fetchInstallations(ctx context.Context) ([]installation, error)
327328
return nil, fmt.Errorf("%s: %w", errUnableToGetInstallations, err)
328329
}
329330

330-
defer res.Body.Close()
331+
defer res.Body.Close() //nolint:errcheck
331332

332333
if statusCode(res.StatusCode).Unsuccessful() {
333334
var bodyBytes []byte
@@ -409,7 +410,7 @@ func (c *Client) RevokeToken(ctx context.Context, token string) (*logical.Respon
409410
return nil, fmt.Errorf("%s: %w", errUnableToRevokeAccessToken, err)
410411
}
411412

412-
defer res.Body.Close()
413+
defer res.Body.Close() //nolint:errcheck
413414

414415
if !statusCode(res.StatusCode).Revoked() {
415416
var bodyBytes []byte

github/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func NewConfig() *Config {
4646

4747
// Update updates the configuration from the given field data only when the data
4848
// is different.
49-
func (c *Config) Update(d *framework.FieldData) (bool, error) {
49+
func (c *Config) Update(d *framework.FieldData) (bool, error) { //nolint:cyclop
5050
if d == nil {
5151
// NOTE: Use of the path framework ensures `d` is never nil.
5252
return false, errFieldDataNil

0 commit comments

Comments
 (0)