Skip to content

Commit 360de21

Browse files
authored
ci: upgrade golangci-lint and enable misspell linter (#4540)
* ci: upgrade golangci-lint * refactor: apply `golangci-lint run --fix` * refactor: manually address some lint issues * fix: fix misspelled words I'm not the only one :)
1 parent 09dbe1e commit 360de21

File tree

42 files changed

+196
-223
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+196
-223
lines changed

.github/workflows/checks.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@ jobs:
4141
- uses: actions/setup-go@v5
4242
with:
4343
go-version-file: "go.mod"
44-
- uses: golangci/golangci-lint-action@v6
44+
- uses: golangci/golangci-lint-action@v8
4545
with:
46-
version: v1.64
46+
version: v2.4.0

.golangci.yml

Lines changed: 64 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,71 @@
1-
issues:
2-
# List of regexps of issue texts to exclude, empty list by default.
3-
# But independently from this option we use default exclude patterns,
4-
# it can be disabled by `exclude-use-default: false`. To list all
5-
# excluded by default patterns execute `golangci-lint run --help`
6-
7-
exclude-rules:
8-
# Exclude gosimple bool check
9-
- linters:
10-
- gosimple
11-
text: "S(1002|1008|1021)"
12-
# Exclude failing staticchecks for now
13-
- linters:
14-
- staticcheck
15-
text: "SA(1006|1019|4006|4010|4017|5007|6005|9004):"
16-
# Exclude lll issues for long lines with go:generate
17-
- linters:
18-
- lll
19-
source: "^//go:generate "
20-
21-
# Maximum issues count per one linter. Set to 0 to disable. Default is 50.
22-
max-issues-per-linter: 0
23-
24-
# Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
25-
max-same-issues: 0
26-
1+
version: "2"
2+
run:
3+
concurrency: 4
4+
go: "1.21"
5+
issues-exit-code: 1
6+
tests: true
277
linters:
28-
disable-all: true
8+
default: none
299
enable:
30-
- gofmt
31-
- gosimple
3210
- govet
3311
- ineffassign
3412
- staticcheck
3513
- unconvert
3614
- unused
37-
38-
# options for analysis running
39-
run:
40-
go: "1.21"
41-
42-
# default concurrency is a available CPU number
43-
concurrency: 4
44-
45-
# timeout for analysis, e.g. 30s, 5m, default is 1m
46-
timeout: 10m
47-
48-
# exit code when at least one issue was found, default is 1
49-
issues-exit-code: 1
50-
51-
# include test files or not, default is true
52-
tests: true
53-
54-
# list of build tags, all linters use it. Default is empty list.
55-
#build-tags:
56-
# - mytag
57-
# - lib/bad.go
58-
59-
# by default isn't set. If set we pass it to "go list -mod={option}". From "go help modules":
60-
# If invoked with -mod=readonly, the go command is disallowed from the implicit
61-
# automatic updating of go.mod described above. Instead, it fails when any changes
62-
# to go.mod are needed. This setting is most useful to check that go.mod does
63-
# not need updates, such as in a continuous integration and testing system.
64-
# If invoked with -mod=vendor, the go command assumes that the vendor
65-
# directory holds the correct copies of dependencies and ignores
66-
# the dependency descriptions in go.mod.
67-
# modules-download-mode: vendor
68-
69-
# output configuration options
70-
output:
71-
# print lines of code with issue, default is true
72-
print-issued-lines: true
73-
74-
# print linter name in the end of issue text, default is true
75-
print-linter-name: true
76-
77-
78-
sort-results: true
79-
80-
# all available settings of specific linters
81-
linters-settings:
82-
errcheck:
83-
exclude-functions:
84-
- fmt.*
85-
- io.Close
86-
govet:
87-
settings:
88-
printf:
89-
funcs:
90-
- github.com/superfly/flyctl/terminal.Debugf
91-
- github.com/superfly/flyctl/terminal.Infof
92-
- github.com/superfly/flyctl/terminal.Warnf
93-
- github.com/superfly/flyctl/terminal.Errorf
94-
- github.com/superfly/flyctl/render.Printf
95-
- github.com/superfly/flyctl/render.Detailf
96-
- github.com/superfly/flyctl/render.Donef
15+
- misspell
16+
settings:
17+
errcheck:
18+
exclude-functions:
19+
- fmt.*
20+
- io.Close
21+
govet:
22+
settings:
23+
printf:
24+
funcs:
25+
- github.com/superfly/flyctl/terminal.Debugf
26+
- github.com/superfly/flyctl/terminal.Infof
27+
- github.com/superfly/flyctl/terminal.Warnf
28+
- github.com/superfly/flyctl/terminal.Errorf
29+
- github.com/superfly/flyctl/render.Printf
30+
- github.com/superfly/flyctl/render.Detailf
31+
- github.com/superfly/flyctl/render.Donef
32+
staticcheck:
33+
checks:
34+
- all
35+
- -SA1019 # ... is deprecated
36+
- -ST1003 # struct field ... should be ... (mostly acronyms such as Http -> HTTP)
37+
- -ST1005 # error strings should not be capitalized
38+
- -ST1008 # error should be returned as the last argument
39+
- -ST1012 # error var ... should have name of the form Err...
40+
- -QF1001 # could apply De Morgan's law
41+
- -QF1002 # could use tagged switch
42+
- -QF1003 # could use tagged switch on app
43+
- -QF1008 # could remove embedded field ... from selector
44+
- -QF1012 # Use fmt.Fprintf(...) instead of WriteString(fmt.Sprintf(...))
45+
exclusions:
46+
generated: lax
47+
presets:
48+
- comments
49+
- common-false-positives
50+
- legacy
51+
- std-error-handling
52+
rules:
53+
- linters:
54+
- lll
55+
source: '^//go:generate '
56+
paths:
57+
- third_party$
58+
- builtin$
59+
- examples$
60+
issues:
61+
max-issues-per-linter: 0
62+
max-same-issues: 0
63+
formatters:
64+
enable:
65+
- gofmt
66+
exclusions:
67+
generated: lax
68+
paths:
69+
- third_party$
70+
- builtin$
71+
- examples$

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ repos:
1818
# because goalngci-lint github action is much more useful than the pre-commit action.
1919
# The trick is to run github action only for "manual" hook stage
2020
- repo: https://github.com/golangci/golangci-lint
21-
rev: v1.54.2
21+
rev: v1.24.0
2222
hooks:
2323
- id: golangci-lint
2424
stages: [pre-commit]

agent/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func Establish(ctx context.Context, apiClient wireguard.WebClient) (*Client, err
5959
return c, nil
6060
}
6161

62-
// TOOD: log this instead
62+
// TODO: log this instead
6363
msg := fmt.Sprintf("The running flyctl agent (v%s) is older than the current flyctl (v%s).", res.Version, buildinfo.Version())
6464

6565
logger := logger.MaybeFromContext(ctx)

doc/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ func GenMarkdownCustom(cmd *cobra.Command, w io.Writer, linkHandler func(string)
110110
}
111111
cname := name + " " + child.Name()
112112
link := cname + ".md"
113-
link = strings.Replace(link, " ", "_", -1)
113+
link = strings.ReplaceAll(link, " ", "_")
114114
buf.WriteString(fmt.Sprintf("* [%s](%s)\t - %s\n", child.Name(), linkHandler(link), child.Short))
115115
}
116116
buf.WriteString("\n")
@@ -130,7 +130,7 @@ func GenMarkdownCustom(cmd *cobra.Command, w io.Writer, linkHandler func(string)
130130
parent := cmd.Parent()
131131
pname := parent.CommandPath()
132132
link := pname + ".md"
133-
link = strings.Replace(link, " ", "_", -1)
133+
link = strings.ReplaceAll(link, " ", "_")
134134
buf.WriteString(fmt.Sprintf("* [%s](%s)\t - %s\n", pname, linkHandler(link), parent.Short))
135135
cmd.VisitParents(func(c *cobra.Command) {
136136
if c.DisableAutoGenTag {
@@ -172,7 +172,7 @@ func GenMarkdownTreeCustom(cmd *cobra.Command, dir string, filePrepender, linkHa
172172
}
173173
}
174174

175-
basename := strings.Replace(cmd.CommandPath(), " ", "_", -1) + ".md"
175+
basename := strings.ReplaceAll(cmd.CommandPath(), " ", "_") + ".md"
176176
filename := filepath.Join(dir, basename)
177177
f, err := os.Create(filename)
178178
if err != nil {

internal/appconfig/config.go

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -298,48 +298,48 @@ func (c *Config) InternalPort() int {
298298
return 0
299299
}
300300

301-
func (cfg *Config) BuildStrategies() []string {
301+
func (c *Config) BuildStrategies() []string {
302302
strategies := []string{}
303303

304-
if cfg == nil || cfg.Build == nil {
304+
if c == nil || c.Build == nil {
305305
return strategies
306306
}
307307

308-
if cfg.Build.Image != "" {
309-
strategies = append(strategies, fmt.Sprintf("the \"%s\" docker image", cfg.Build.Image))
308+
if c.Build.Image != "" {
309+
strategies = append(strategies, fmt.Sprintf("the \"%s\" docker image", c.Build.Image))
310310
}
311-
if cfg.Build.Builder != "" || len(cfg.Build.Buildpacks) > 0 {
311+
if c.Build.Builder != "" || len(c.Build.Buildpacks) > 0 {
312312
strategies = append(strategies, "a buildpack")
313313
}
314-
if cfg.Build.Dockerfile != "" || cfg.Build.DockerBuildTarget != "" {
315-
if cfg.Build.Dockerfile != "" {
316-
strategies = append(strategies, fmt.Sprintf("the \"%s\" dockerfile", cfg.Build.Dockerfile))
314+
if c.Build.Dockerfile != "" || c.Build.DockerBuildTarget != "" {
315+
if c.Build.Dockerfile != "" {
316+
strategies = append(strategies, fmt.Sprintf("the \"%s\" dockerfile", c.Build.Dockerfile))
317317
} else {
318318
strategies = append(strategies, "a dockerfile")
319319
}
320320
}
321-
if cfg.Build.Builtin != "" {
322-
strategies = append(strategies, fmt.Sprintf("the \"%s\" builtin image", cfg.Build.Builtin))
321+
if c.Build.Builtin != "" {
322+
strategies = append(strategies, fmt.Sprintf("the \"%s\" builtin image", c.Build.Builtin))
323323
}
324324

325325
return strategies
326326
}
327327

328-
func (cfg *Config) URL() *url.URL {
328+
func (c *Config) URL() *url.URL {
329329
u := &url.URL{
330330
Scheme: "https",
331-
Host: cfg.AppName + ".fly.dev",
331+
Host: c.AppName + ".fly.dev",
332332
Path: "/",
333333
}
334334

335335
// HTTPService always listen on https, even if ForceHTTPS is false
336-
if cfg.HTTPService != nil && cfg.HTTPService.InternalPort > 0 {
336+
if c.HTTPService != nil && c.HTTPService.InternalPort > 0 {
337337
return u
338338
}
339339

340340
var httpPorts []int
341341
var httpsPorts []int
342-
for _, service := range cfg.Services {
342+
for _, service := range c.Services {
343343
for _, port := range service.Ports {
344344
if port.Port == nil || !slices.Contains(port.Handlers, "http") {
345345
continue
@@ -374,10 +374,10 @@ func (cfg *Config) URL() *url.URL {
374374

375375
// MergeFiles merges the provided files with the files in the config wherein the provided files
376376
// take precedence.
377-
func (cfg *Config) MergeFiles(files []*fly.File) error {
377+
func (c *Config) MergeFiles(files []*fly.File) error {
378378
// First convert the Config files to Machine files.
379-
cfgFiles := make([]*fly.File, 0, len(cfg.Files))
380-
for _, f := range cfg.Files {
379+
cfgFiles := make([]*fly.File, 0, len(c.Files))
380+
for _, f := range c.Files {
381381
machineFile, err := f.toMachineFile()
382382
if err != nil {
383383
return err
@@ -392,29 +392,29 @@ func (cfg *Config) MergeFiles(files []*fly.File) error {
392392
fly.MergeFiles(mConfig, files)
393393

394394
// Persist the merged files back to the config to be used later for deploying.
395-
cfg.MergedFiles = mConfig.Files
395+
c.MergedFiles = mConfig.Files
396396

397397
return nil
398398
}
399399

400-
func (cfg *Config) DeployStrategy() string {
401-
if cfg.Deploy == nil {
400+
func (c *Config) DeployStrategy() string {
401+
if c.Deploy == nil {
402402
return ""
403403
}
404-
return cfg.Deploy.Strategy
404+
return c.Deploy.Strategy
405405
}
406406

407407
// DetectComposeFile returns Build.Compose.File if set, otherwise looks for
408408
// well-known compose filenames in the directory containing the config file.
409409
// Returns the first found filename or empty string.
410-
func (cfg *Config) DetectComposeFile() string {
410+
func (c *Config) DetectComposeFile() string {
411411
// If compose file is explicitly set, return it
412-
if cfg.Build != nil && cfg.Build.Compose != nil && cfg.Build.Compose.File != "" {
413-
return cfg.Build.Compose.File
412+
if c.Build != nil && c.Build.Compose != nil && c.Build.Compose.File != "" {
413+
return c.Build.Compose.File
414414
}
415415

416416
// Otherwise, detect well-known filenames
417-
configDir := filepath.Dir(cfg.configFilePath)
417+
configDir := filepath.Dir(c.configFilePath)
418418

419419
for _, filename := range WellKnownComposeFilenames {
420420
path := filepath.Join(configDir, filename)

internal/appconfig/machines.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ func (c *Config) ToConsoleMachineConfig() (*fly.MachineConfig, error) {
239239

240240
// updateMachineConfig applies configuration options from the optional MachineConfig passed in, then the base config, into a new MachineConfig
241241
func (c *Config) updateMachineConfig(src *fly.MachineConfig) (*fly.MachineConfig, error) {
242-
// For flattened app configs there is only one proces name and it is the group it was flattened for
242+
// For flattened app configs there is only one process name and it is the group it was flattened for
243243
processGroup := c.DefaultProcessName()
244244

245245
mConfig := &fly.MachineConfig{}

0 commit comments

Comments
 (0)