Skip to content

Commit

Permalink
Merge pull request #2828 from dgageot/add-gosimple-linter
Browse files Browse the repository at this point in the history
Enable gosimple linter
  • Loading branch information
tonistiigi committed Apr 27, 2022
2 parents ed5f454 + 1245e43 commit 3eed7fd
Show file tree
Hide file tree
Showing 18 changed files with 22 additions and 41 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Expand Up @@ -14,6 +14,7 @@ linters:
- depguard
- gofmt
- goimports
- gosimple
- revive
- govet
- importas
Expand Down
4 changes: 1 addition & 3 deletions cache/metadata.go
Expand Up @@ -551,9 +551,7 @@ func (md *cacheMetadata) appendStringSlice(key string, values ...string) error {
}

for _, existing := range slice {
if _, ok := idx[existing]; ok {
delete(idx, existing)
}
delete(idx, existing)
}

if len(idx) == 0 {
Expand Down
1 change: 0 additions & 1 deletion client/client_test.go
Expand Up @@ -912,7 +912,6 @@ func testFrontendImageNaming(t *testing.T, sb integration.Sandbox) {
checkImageName := map[string]func(out, imageName string, exporterResponse map[string]string){
ExporterOCI: func(out, imageName string, exporterResponse map[string]string) {
// Nothing to check
return
},
ExporterDocker: func(out, imageName string, exporterResponse map[string]string) {
require.Contains(t, exporterResponse, "image.name")
Expand Down
5 changes: 1 addition & 4 deletions client/llb/marshal.go
Expand Up @@ -87,10 +87,7 @@ func MarshalConstraints(base, override *Constraints) (*pb.Op, *pb.OpMetadata) {
c.Platform = p
}

for _, wc := range override.WorkerConstraints {
c.WorkerConstraints = append(c.WorkerConstraints, wc)
}

c.WorkerConstraints = append(c.WorkerConstraints, override.WorkerConstraints...)
c.Metadata = mergeMetadata(c.Metadata, override.Metadata)

if c.Platform == nil {
Expand Down
4 changes: 1 addition & 3 deletions client/llb/state.go
Expand Up @@ -619,9 +619,7 @@ var (

func Require(filters ...string) ConstraintsOpt {
return constraintsOptFunc(func(c *Constraints) {
for _, f := range filters {
c.WorkerConstraints = append(c.WorkerConstraints, f)
}
c.WorkerConstraints = append(c.WorkerConstraints, filters...)
})
}

Expand Down
2 changes: 1 addition & 1 deletion exporter/containerimage/writer.go
Expand Up @@ -426,7 +426,7 @@ func patchImageConfig(dt []byte, descs []ocispecs.Descriptor, history []ocispecs
return nil, err
}
m[binfotypes.ImageConfigField] = dt
} else if _, ok := m[binfotypes.ImageConfigField]; ok {
} else {
delete(m, binfotypes.ImageConfigField)
}

Expand Down
3 changes: 1 addition & 2 deletions frontend/dockerfile/dockerignore/dockerignore_test.go
@@ -1,7 +1,6 @@
package dockerignore

import (
"fmt"
"os"
"path/filepath"
"testing"
Expand All @@ -24,7 +23,7 @@ func TestReadAll(t *testing.T) {
}

diName := filepath.Join(tmpDir, ".dockerignore")
content := fmt.Sprintf("test1\n/test2\n/a/file/here\n\nlastfile\n# this is a comment\n! /inverted/abs/path\n!\n! \n")
content := "test1\n/test2\n/a/file/here\n\nlastfile\n# this is a comment\n! /inverted/abs/path\n!\n! \n"
err = os.WriteFile(diName, []byte(content), 0777)
if err != nil {
t.Fatal(err)
Expand Down
4 changes: 2 additions & 2 deletions frontend/gateway/gateway.go
Expand Up @@ -651,7 +651,7 @@ func (lbf *llbBridgeForwarder) Solve(ctx context.Context, req *pb.SolveRequest)
if err != nil {
return nil, err
}
if dtbi != nil && len(dtbi) > 0 {
if len(dtbi) > 0 {
if pbRes.Metadata == nil {
pbRes.Metadata = make(map[string][]byte)
}
Expand Down Expand Up @@ -684,7 +684,7 @@ func (lbf *llbBridgeForwarder) Solve(ctx context.Context, req *pb.SolveRequest)
if err != nil {
return nil, err
}
if dtbi != nil && len(dtbi) > 0 {
if len(dtbi) > 0 {
if pbRes.Metadata == nil {
pbRes.Metadata = make(map[string][]byte)
}
Expand Down
10 changes: 4 additions & 6 deletions session/manager.go
Expand Up @@ -160,12 +160,10 @@ func (sm *Manager) Get(ctx context.Context, id string, noWait bool) (Caller, err
defer cancel()

go func() {
select {
case <-ctx.Done():
sm.mu.Lock()
sm.updateCondition.Broadcast()
sm.mu.Unlock()
}
<-ctx.Done()
sm.mu.Lock()
sm.updateCondition.Broadcast()
sm.mu.Unlock()
}()

var c *client
Expand Down
4 changes: 1 addition & 3 deletions solver/jobs.go
Expand Up @@ -551,9 +551,7 @@ func (j *Job) Discard() error {
delete(st.jobs, j)
j.list.deleteIfUnreferenced(k, st)
}
if _, ok := st.allPw[j.pw]; ok {
delete(st.allPw, j.pw)
}
delete(st.allPw, j.pw)
st.mu.Unlock()
}

Expand Down
4 changes: 2 additions & 2 deletions solver/llbsolver/bridge.go
Expand Up @@ -165,7 +165,7 @@ func (b *llbBridge) Solve(ctx context.Context, req frontend.SolveRequest, sid st
if err != nil {
return nil, err
}
if dtbi != nil && len(dtbi) > 0 {
if len(dtbi) > 0 {
if res.Metadata == nil {
res.Metadata = make(map[string][]byte)
}
Expand All @@ -177,7 +177,7 @@ func (b *llbBridge) Solve(ctx context.Context, req frontend.SolveRequest, sid st
if err != nil {
return nil, err
}
if dtbi != nil && len(dtbi) > 0 {
if len(dtbi) > 0 {
if res.Metadata == nil {
res.Metadata = make(map[string][]byte)
}
Expand Down
4 changes: 2 additions & 2 deletions solver/llbsolver/solver.go
Expand Up @@ -174,7 +174,7 @@ func (s *Solver) Solve(ctx context.Context, id string, sessionID string, req fro
if err != nil {
return nil, err
}
if dtbi != nil && len(dtbi) > 0 {
if len(dtbi) > 0 {
if res.Metadata == nil {
res.Metadata = make(map[string][]byte)
}
Expand All @@ -190,7 +190,7 @@ func (s *Solver) Solve(ctx context.Context, id string, sessionID string, req fro
if err != nil {
return nil, err
}
if dtbi != nil && len(dtbi) > 0 {
if len(dtbi) > 0 {
if res.Metadata == nil {
res.Metadata = make(map[string][]byte)
}
Expand Down
3 changes: 1 addition & 2 deletions solver/scheduler.go
Expand Up @@ -222,8 +222,7 @@ func (s *scheduler) build(ctx context.Context, edge Edge) (CachedResult, error)

wait := make(chan struct{})

var p *pipe.Pipe
p = s.newPipe(e, nil, pipe.Request{Payload: &edgeRequest{desiredState: edgeStatusComplete}})
p := s.newPipe(e, nil, pipe.Request{Payload: &edgeRequest{desiredState: edgeStatusComplete}})
p.OnSendCompletion = func() {
p.Receiver.Receive()
if p.Receiver.Status().Completed {
Expand Down
2 changes: 1 addition & 1 deletion source/containerimage/pull.go
Expand Up @@ -178,7 +178,7 @@ func (p *puller) CacheKey(ctx context.Context, g session.Group, index int) (cach
progressFactory := progress.FromContext(ctx)

_, err = p.g.Do(ctx, "", func(ctx context.Context) (_ interface{}, err error) {
if p.cacheKeyErr != nil || p.cacheKeyDone == true {
if p.cacheKeyErr != nil || p.cacheKeyDone {
return nil, p.cacheKeyErr
}
defer func() {
Expand Down
4 changes: 1 addition & 3 deletions util/progress/multiwriter.go
Expand Up @@ -36,9 +36,7 @@ func (ps *MultiWriter) Add(pw Writer) {
}
ps.mu.Lock()
plist := make([]*Progress, 0, len(ps.items))
for _, p := range ps.items {
plist = append(plist, p)
}
plist = append(plist, ps.items...)
sort.Slice(plist, func(i, j int) bool {
return plist[i].Timestamp.Before(plist[j].Timestamp)
})
Expand Down
2 changes: 1 addition & 1 deletion util/throttle/throttle.go
Expand Up @@ -31,7 +31,7 @@ func throttle(d time.Duration, f func(), wait bool) func() {
go func() {
for {
mu.Lock()
if next == false {
if !next {
running = false
mu.Unlock()
return
Expand Down
5 changes: 1 addition & 4 deletions util/winlayers/context.go
Expand Up @@ -12,8 +12,5 @@ func UseWindowsLayerMode(ctx context.Context) context.Context {

func hasWindowsLayerMode(ctx context.Context) bool {
v := ctx.Value(contextKey)
if v == nil {
return false
}
return true
return v != nil
}
1 change: 0 additions & 1 deletion util/winlayers/differ.go
Expand Up @@ -262,7 +262,6 @@ func makeWindowsLayer(w io.Writer) (io.Writer, func(error), chan error) {
}
pw.CloseWithError(err)
done <- err
return
}()

discard := func(err error) {
Expand Down

0 comments on commit 3eed7fd

Please sign in to comment.