Skip to content

Commit

Permalink
Add gosimple linter
Browse files Browse the repository at this point in the history
Update gometalinter

Signed-off-by: Daniel Nephin <dnephin@docker.com>
  • Loading branch information
dnephin committed Sep 12, 2017
1 parent 969b76d commit f7f101d
Show file tree
Hide file tree
Showing 52 changed files with 137 additions and 271 deletions.
11 changes: 2 additions & 9 deletions api/server/httputils/write_log_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,13 @@ import (

// WriteLogStream writes an encoded byte stream of log messages from the
// messages channel, multiplexing them with a stdcopy.Writer if mux is true
func WriteLogStream(ctx context.Context, w io.Writer, msgs <-chan *backend.LogMessage, config *types.ContainerLogsOptions, mux bool) {
func WriteLogStream(_ context.Context, w io.Writer, msgs <-chan *backend.LogMessage, config *types.ContainerLogsOptions, mux bool) {
wf := ioutils.NewWriteFlusher(w)
defer wf.Close()

wf.Flush()

// this might seem like doing below is clear:
// var outStream io.Writer = wf
// however, this GREATLY DISPLEASES golint, and if you do that, it will
// fail CI. we need outstream to be type writer because if we mux streams,
// we will need to reassign all of the streams to be stdwriters, which only
// conforms to the io.Writer interface.
var outStream io.Writer
outStream = wf
outStream := io.Writer(wf)
errStream := outStream
sysErrStream := errStream
if mux {
Expand Down
12 changes: 2 additions & 10 deletions api/server/router/swarm/cluster_routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -427,11 +427,7 @@ func (sr *swarmRouter) updateSecret(ctx context.Context, w http.ResponseWriter,
}

id := vars["id"]
if err := sr.backend.UpdateSecret(id, version, secret); err != nil {
return err
}

return nil
return sr.backend.UpdateSecret(id, version, secret)
}

func (sr *swarmRouter) getConfigs(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
Expand Down Expand Up @@ -498,9 +494,5 @@ func (sr *swarmRouter) updateConfig(ctx context.Context, w http.ResponseWriter,
}

id := vars["id"]
if err := sr.backend.UpdateConfig(id, version, config); err != nil {
return err
}

return nil
return sr.backend.UpdateConfig(id, version, config)
}
4 changes: 2 additions & 2 deletions api/types/filters/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func TestArgsMatchKVList(t *testing.T) {
}

for args, field := range matches {
if args.MatchKVList(field, sources) != true {
if !args.MatchKVList(field, sources) {
t.Fatalf("Expected true for %v on %v, got false", sources, args)
}
}
Expand All @@ -202,7 +202,7 @@ func TestArgsMatchKVList(t *testing.T) {
}

for args, field := range differs {
if args.MatchKVList(field, sources) != false {
if args.MatchKVList(field, sources) {
t.Fatalf("Expected false for %v on %v, got true", sources, args)
}
}
Expand Down
4 changes: 1 addition & 3 deletions api/types/time/timestamp.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ func GetTimestamp(value string, reference time.Time) (string, error) {
}

var format string
var parseInLocation bool

// if the string has a Z or a + or three dashes use parse otherwise use parseinlocation
parseInLocation = !(strings.ContainsAny(value, "zZ+") || strings.Count(value, "-") == 3)
parseInLocation := !(strings.ContainsAny(value, "zZ+") || strings.Count(value, "-") == 3)

if strings.Contains(value, ".") {
if parseInLocation {
Expand Down
8 changes: 4 additions & 4 deletions builder/dockerfile/bflag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ func TestBuilderFlags(t *testing.T) {
t.Fatalf("Test3 of %q was supposed to work: %s", bf.Args, err)
}

if flStr1.IsUsed() == true {
if flStr1.IsUsed() {
t.Fatal("Test3 - str1 was not used!")
}
if flBool1.IsUsed() == true {
if flBool1.IsUsed() {
t.Fatal("Test3 - bool1 was not used!")
}

Expand All @@ -58,10 +58,10 @@ func TestBuilderFlags(t *testing.T) {
if flBool1.IsTrue() {
t.Fatal("Bool1 was supposed to default to: false")
}
if flStr1.IsUsed() == true {
if flStr1.IsUsed() {
t.Fatal("Str1 was not used!")
}
if flBool1.IsUsed() == true {
if flBool1.IsUsed() {
t.Fatal("Bool1 was not used!")
}

Expand Down
10 changes: 2 additions & 8 deletions builder/dockerfile/internals.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,10 +206,7 @@ func lookupUser(userStr, filepath string) (int, error) {
return uid, nil
}
users, err := lcUser.ParsePasswdFileFilter(filepath, func(u lcUser.User) bool {
if u.Name == userStr {
return true
}
return false
return u.Name == userStr
})
if err != nil {
return 0, err
Expand All @@ -228,10 +225,7 @@ func lookupGroup(groupStr, filepath string) (int, error) {
return gid, nil
}
groups, err := lcUser.ParseGroupFileFilter(filepath, func(g lcUser.Group) bool {
if g.Name == groupStr {
return true
}
return false
return g.Name == groupStr
})
if err != nil {
return 0, err
Expand Down
4 changes: 2 additions & 2 deletions builder/dockerfile/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ func (d *Directive) possibleParserDirective(line string) error {
if len(tecMatch) != 0 {
for i, n := range tokenEscapeCommand.SubexpNames() {
if n == "escapechar" {
if d.escapeSeen == true {
if d.escapeSeen {
return errors.New("only one escape parser directive can be used")
}
d.escapeSeen = true
Expand All @@ -159,7 +159,7 @@ func (d *Directive) possibleParserDirective(line string) error {
if len(tpcMatch) != 0 {
for i, n := range tokenPlatformCommand.SubexpNames() {
if n == "platform" {
if d.platformSeen == true {
if d.platformSeen {
return errors.New("only one platform parser directive can be used")
}
d.platformSeen = true
Expand Down
2 changes: 1 addition & 1 deletion builder/remotecontext/detect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const (
const shouldStayFilename = "should_stay"

func extractFilenames(files []os.FileInfo) []string {
filenames := make([]string, len(files), len(files))
filenames := make([]string, len(files))

for i, file := range files {
filenames[i] = file.Name()
Expand Down
2 changes: 1 addition & 1 deletion builder/remotecontext/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func inspectResponse(ct string, r io.Reader, clen int64) (string, io.ReadCloser,
plen = maxPreambleLength
}

preamble := make([]byte, plen, plen)
preamble := make([]byte, plen)
rlen, err := r.Read(preamble)
if rlen == 0 {
return ct, ioutil.NopCloser(r), errors.New("empty response")
Expand Down
2 changes: 1 addition & 1 deletion client/container_commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (cli *Client) ContainerCommit(ctx context.Context, container string, option
for _, change := range options.Changes {
query.Add("changes", change)
}
if options.Pause != true {
if !options.Pause {
query.Set("pause", "0")
}

Expand Down
2 changes: 1 addition & 1 deletion client/hijack.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func tlsDialWithDialer(dialer *net.Dialer, network, addr string, config *tls.Con
timeout := dialer.Timeout

if !dialer.Deadline.IsZero() {
deadlineTimeout := dialer.Deadline.Sub(time.Now())
deadlineTimeout := time.Until(dialer.Deadline)
if timeout == 0 || deadlineTimeout < timeout {
timeout = deadlineTimeout
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/dockerd/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ func loadDaemonCliConfig(opts *daemonOptions) (*config.Config, error) {
return nil, err
}

if conf.V2Only == false {
if !conf.V2Only {
logrus.Warnf(`The "disable-legacy-registry" option is deprecated and wil be removed in Docker v17.12. Interacting with legacy (v1) registries will no longer be supported in Docker v17.12"`)
}

Expand Down
5 changes: 1 addition & 4 deletions container/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,7 @@ func (db *memDB) ReserveName(name, containerID string) error {
// Once released, a name can be reserved again
func (db *memDB) ReleaseName(name string) error {
return db.withTxn(func(txn *memdb.Txn) error {
if err := txn.Delete(memdbNamesTable, nameAssociation{name: name}); err != nil {
return err
}
return nil
return txn.Delete(memdbNamesTable, nameAssociation{name: name})
})
}

Expand Down
9 changes: 0 additions & 9 deletions contrib/docker-device-tool/device_tool.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,14 +90,12 @@ func main() {
fmt.Printf("Sector size: %d\n", status.SectorSize)
fmt.Printf("Data use: %d of %d (%.1f %%)\n", status.Data.Used, status.Data.Total, 100.0*float64(status.Data.Used)/float64(status.Data.Total))
fmt.Printf("Metadata use: %d of %d (%.1f %%)\n", status.Metadata.Used, status.Metadata.Total, 100.0*float64(status.Metadata.Used)/float64(status.Metadata.Total))
break
case "list":
ids := devices.List()
sort.Strings(ids)
for _, id := range ids {
fmt.Println(id)
}
break
case "device":
if flag.NArg() < 2 {
usage()
Expand All @@ -113,7 +111,6 @@ func main() {
fmt.Printf("Size in Sectors: %d\n", status.SizeInSectors)
fmt.Printf("Mapped Sectors: %d\n", status.MappedSectors)
fmt.Printf("Highest Mapped Sector: %d\n", status.HighestMappedSector)
break
case "resize":
if flag.NArg() < 2 {
usage()
Expand All @@ -131,7 +128,6 @@ func main() {
os.Exit(1)
}

break
case "snap":
if flag.NArg() < 3 {
usage()
Expand All @@ -142,7 +138,6 @@ func main() {
fmt.Println("Can't create snap device: ", err)
os.Exit(1)
}
break
case "remove":
if flag.NArg() < 2 {
usage()
Expand All @@ -153,7 +148,6 @@ func main() {
fmt.Println("Can't remove device: ", err)
os.Exit(1)
}
break
case "mount":
if flag.NArg() < 3 {
usage()
Expand All @@ -164,13 +158,10 @@ func main() {
fmt.Println("Can't mount device: ", err)
os.Exit(1)
}
break
default:
fmt.Printf("Unknown command %s\n", args[0])
usage()

os.Exit(1)
}

return
}
12 changes: 2 additions & 10 deletions daemon/cluster/executor/container/attachment.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,7 @@ func (nc *networkAttacherController) Update(ctx context.Context, t *api.Task) er

func (nc *networkAttacherController) Prepare(ctx context.Context) error {
// Make sure all the networks that the task needs are created.
if err := nc.adapter.createNetworks(ctx); err != nil {
return err
}

return nil
return nc.adapter.createNetworks(ctx)
}

func (nc *networkAttacherController) Start(ctx context.Context) error {
Expand All @@ -69,11 +65,7 @@ func (nc *networkAttacherController) Terminate(ctx context.Context) error {
func (nc *networkAttacherController) Remove(ctx context.Context) error {
// Try removing the network referenced in this task in case this
// task is the last one referencing it
if err := nc.adapter.removeNetworks(ctx); err != nil {
return err
}

return nil
return nc.adapter.removeNetworks(ctx)
}

func (nc *networkAttacherController) Close() error {
Expand Down
19 changes: 7 additions & 12 deletions daemon/config/config_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ import (
"testing"

"github.com/docker/docker/opts"
"github.com/docker/go-units"
units "github.com/docker/go-units"
"github.com/gotestyourself/gotestyourself/fs"
"github.com/spf13/pflag"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

func TestGetConflictFreeConfiguration(t *testing.T) {
configFileData := string([]byte(`
configFileData := `
{
"debug": true,
"default-ulimits": {
Expand All @@ -27,7 +27,7 @@ func TestGetConflictFreeConfiguration(t *testing.T) {
"log-opts": {
"tag": "test_tag"
}
}`))
}`

file := fs.NewFile(t, "docker-config", fs.WithContent(configFileData))
defer file.Remove()
Expand Down Expand Up @@ -55,7 +55,7 @@ func TestGetConflictFreeConfiguration(t *testing.T) {
}

func TestDaemonConfigurationMerge(t *testing.T) {
configFileData := string([]byte(`
configFileData := `
{
"debug": true,
"default-ulimits": {
Expand All @@ -68,7 +68,7 @@ func TestDaemonConfigurationMerge(t *testing.T) {
"log-opts": {
"tag": "test_tag"
}
}`))
}`

file := fs.NewFile(t, "docker-config", fs.WithContent(configFileData))
defer file.Remove()
Expand Down Expand Up @@ -115,10 +115,7 @@ func TestDaemonConfigurationMerge(t *testing.T) {
}

func TestDaemonConfigurationMergeShmSize(t *testing.T) {
data := string([]byte(`
{
"default-shm-size": "1g"
}`))
data := `{"default-shm-size": "1g"}`

file := fs.NewFile(t, "docker-config", fs.WithContent(data))
defer file.Remove()
Expand All @@ -133,7 +130,5 @@ func TestDaemonConfigurationMergeShmSize(t *testing.T) {
require.NoError(t, err)

expectedValue := 1 * 1024 * 1024 * 1024
if cc.ShmSize.Value() != int64(expectedValue) {
t.Fatalf("expected default shm size %d, got %d", expectedValue, cc.ShmSize.Value())
}
assert.Equal(t, int64(expectedValue), cc.ShmSize.Value())
}
2 changes: 1 addition & 1 deletion daemon/exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ type Store struct {

// NewStore initializes a new exec store.
func NewStore() *Store {
return &Store{commands: make(map[string]*Config, 0)}
return &Store{commands: make(map[string]*Config)}
}

// Commands returns the exec configurations in the store.
Expand Down
Loading

0 comments on commit f7f101d

Please sign in to comment.