Skip to content

Commit 4b5bf7e

Browse files
authored
Merge pull request moby#4931 from tonistiigi/golint-updates
lint: enable noctx and gocritic
2 parents 75bbf7b + 265d18f commit 4b5bf7e

File tree

27 files changed

+71
-63
lines changed

27 files changed

+71
-63
lines changed

.golangci.yml

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,36 @@ run:
55

66
linters:
77
enable:
8+
- bodyclose
89
- depguard
10+
- errname
11+
- forbidigo
12+
- gocritic
913
- gofmt
1014
- goimports
15+
- gosec
1116
- gosimple
12-
- revive
1317
- govet
1418
- importas
1519
- ineffassign
20+
- makezero
1621
- misspell
22+
- noctx
23+
- nolintlint
24+
- revive
1725
- staticcheck
1826
- typecheck
1927
- unused
20-
- bodyclose
21-
- errname
22-
- makezero
2328
- whitespace
24-
- nolintlint
25-
- gosec
26-
- forbidigo
2729
disable-all: true
2830

2931
linters-settings:
32+
gocritic:
33+
disabled-checks:
34+
- "ifElseChain"
35+
- "assignOp"
36+
- "appendAssign"
37+
- "singleCaseSwitch"
3038
govet:
3139
enable:
3240
- nilness
@@ -62,8 +70,8 @@ linters-settings:
6270
excludes:
6371
- G101 # Potential hardcoded credentials (false positives)
6472
- G402 # TLS MinVersion too low
65-
- G601 # Implicit memory aliasing in for loop (false positives)
6673
- G504 # Import blocklist: net/http/cgi
74+
- G601 # Implicit memory aliasing in for loop (false positives)
6775
config:
6876
G306: "0644"
6977

cache/contenthash/checksum.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,11 +1176,11 @@ func poolsCopy(dst io.Writer, src io.Reader) (written int64, err error) {
11761176
}
11771177

11781178
func convertPathToKey(p string) []byte {
1179-
return bytes.Replace([]byte(p), []byte("/"), []byte{0}, -1)
1179+
return bytes.ReplaceAll([]byte(p), []byte("/"), []byte{0})
11801180
}
11811181

11821182
func convertKeyToPath(p []byte) string {
1183-
return string(bytes.Replace(p, []byte{0}, []byte("/"), -1))
1183+
return string(bytes.ReplaceAll(p, []byte{0}, []byte("/")))
11841184
}
11851185

11861186
func splitKey(k []byte) ([]byte, []byte) {

client/connhelper/npipe/npipe_windows.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func Helper(u *url.URL) (*connhelper.ConnectionHelper, error) {
1919
if len(addrParts) != 2 {
2020
return nil, errors.Errorf("invalid address %s", u)
2121
}
22-
address := strings.Replace(addrParts[1], "/", "\\", -1)
22+
address := strings.ReplaceAll(addrParts[1], "/", "\\")
2323
return &connhelper.ConnectionHelper{
2424
ContextDialer: func(ctx context.Context, addr string) (net.Conn, error) {
2525
return winio.DialPipeContext(ctx, address)

cmd/buildctl/build.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -289,10 +289,8 @@ func buildAction(clicontext *cli.Context) error {
289289
if len(def.Def) == 0 {
290290
return errors.Errorf("empty definition sent to build. Specify --frontend instead?")
291291
}
292-
} else {
293-
if clicontext.Bool("no-cache") {
294-
solveOpt.FrontendAttrs["no-cache"] = ""
295-
}
292+
} else if clicontext.Bool("no-cache") {
293+
solveOpt.FrontendAttrs["no-cache"] = ""
296294
}
297295

298296
refFile := clicontext.String("ref-file")

executor/oci/resolvconf.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,8 @@ func GetResolvConf(ctx context.Context, stateDir string, idmap *idtools.Identity
5353
generate = true
5454
lastNotEmpty = false
5555
}
56-
} else {
57-
if fi.ModTime().Before(fiMain.ModTime()) {
58-
generate = true
59-
}
56+
} else if fi.ModTime().Before(fiMain.ModTime()) {
57+
generate = true
6058
}
6159
}
6260
}

executor/resources/pids_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ func TestParsePidsStat(t *testing.T) {
1919
expectedPidsStat := &resourcestypes.PIDsStat{
2020
Current: uint64Ptr(123),
2121
}
22-
stats, err := getCgroupPIDsStat(filepath.Join(testDir))
22+
stats, err := getCgroupPIDsStat(filepath.Clean(testDir))
2323
require.NoError(t, err)
2424
assert.Equal(t, expectedPidsStat, stats)
2525
}

exporter/local/export.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ func (e *localExporterInstance) Export(ctx context.Context, inp *exporter.Source
142142
if e.opts.PlatformSplit {
143143
st := fstypes.Stat{
144144
Mode: uint32(os.ModeDir | 0755),
145-
Path: strings.Replace(k, "/", "_", -1),
145+
Path: strings.ReplaceAll(k, "/", "_"),
146146
}
147147
if e.opts.Epoch != nil {
148148
st.ModTime = e.opts.Epoch.UnixNano()

exporter/local/fs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ func CreateFS(ctx context.Context, sessionID string, k string, ref cache.Immutab
189189
if !opt.PlatformSplit {
190190
nameExt := path.Ext(name)
191191
namBase := strings.TrimSuffix(name, nameExt)
192-
name = fmt.Sprintf("%s.%s%s", namBase, strings.Replace(k, "/", "_", -1), nameExt)
192+
name = fmt.Sprintf("%s.%s%s", namBase, strings.ReplaceAll(k, "/", "_"), nameExt)
193193
}
194194
if _, ok := names[name]; ok {
195195
return nil, nil, errors.Errorf("duplicate attestation path name %s", name)

exporter/tar/export.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func (e *localExporterInstance) Export(ctx context.Context, inp *exporter.Source
9696

9797
st := fstypes.Stat{
9898
Mode: uint32(os.ModeDir | 0755),
99-
Path: strings.Replace(k, "/", "_", -1),
99+
Path: strings.ReplaceAll(k, "/", "_"),
100100
}
101101
if e.opts.Epoch != nil {
102102
st.ModTime = e.opts.Epoch.UnixNano()

frontend/dockerfile/dockerfile2llb/convert_runmount.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,9 @@ func dispatchRunMounts(d *dispatchState, c *instructions.RunCommand, sources []*
130130
}
131131
if src := path.Join("/", mount.Source); src != "/" {
132132
mountOpts = append(mountOpts, llb.SourcePath(src))
133-
} else {
134-
if mount.UID != nil || mount.GID != nil || mount.Mode != nil {
135-
st = setCacheUIDGID(mount, st)
136-
mountOpts = append(mountOpts, llb.SourcePath("/cache"))
137-
}
133+
} else if mount.UID != nil || mount.GID != nil || mount.Mode != nil {
134+
st = setCacheUIDGID(mount, st)
135+
mountOpts = append(mountOpts, llb.SourcePath("/cache"))
138136
}
139137

140138
out = append(out, llb.AddMount(target, st, mountOpts...))

0 commit comments

Comments
 (0)