Ver código fonte

all: Fix check for empty string (#8456)

Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>
deepsource-autofix[bot] 3 anos atrás
pai
commit
80ec4acb53

+ 1 - 1
cmd/stcrashreceiver/main.go

@@ -90,7 +90,7 @@ func handleFailureFn(dsn, failureDir string) func(w http.ResponseWriter, req *ht
 			for k, v := range r.Extra {
 				pkt.Extra[k] = v
 			}
-			if len(r.Goroutines) != 0 {
+			if r.Goroutines != "" {
 				url, err := saveFailureWithGoroutines(r.FailureData, failureDir)
 				if err != nil {
 					log.Println("Saving failure report:", err)

+ 1 - 1
cmd/syncthing/main.go

@@ -647,7 +647,7 @@ func syncthingMain(options serveOptions) {
 
 	setupSignalHandling(app)
 
-	if len(os.Getenv("GOMAXPROCS")) == 0 {
+	if os.Getenv("GOMAXPROCS") == "" {
 		runtime.GOMAXPROCS(runtime.NumCPU())
 	}
 

+ 1 - 1
lib/config/size.go

@@ -16,7 +16,7 @@ import (
 
 func ParseSize(s string) (Size, error) {
 	s = strings.TrimSpace(s)
-	if len(s) == 0 {
+	if s == "" {
 		return Size{}, nil
 	}
 

+ 1 - 1
lib/discover/local.go

@@ -64,7 +64,7 @@ func NewLocal(id protocol.DeviceID, addr string, addrList AddressLister, evLogge
 		return nil, err
 	}
 
-	if len(host) == 0 {
+	if host == "" {
 		// A broadcast client
 		c.name = "IPv4 local"
 		bcPort, err := strconv.Atoi(port)

+ 1 - 1
lib/fs/util.go

@@ -55,7 +55,7 @@ func WindowsInvalidFilename(name string) error {
 	// None of the path components should end in space or period, or be a
 	// reserved name.
 	for _, part := range strings.Split(name, `\`) {
-		if len(part) == 0 {
+		if part == "" {
 			continue
 		}
 		switch part[len(part)-1] {

+ 1 - 1
lib/model/folder_sendrecv.go

@@ -737,7 +737,7 @@ func (f *sendReceiveFolder) handleSymlink(file protocol.FileInfo, snap *db.Snaps
 		l.Debugf("need symlink\n\t%v\n\t%v", file, curFile)
 	}
 
-	if len(file.SymlinkTarget) == 0 {
+	if file.SymlinkTarget == "" {
 		// Index entry from a Syncthing predating the support for including
 		// the link target in the index entry. We log this as an error.
 		f.newPullError(file.Name, errIncompatibleSymlink)

+ 1 - 1
lib/model/model.go

@@ -511,7 +511,7 @@ func (m *model) cleanupFolderLocked(cfg config.FolderConfiguration) {
 }
 
 func (m *model) restartFolder(from, to config.FolderConfiguration, cacheIgnoredFiles bool) error {
-	if len(to.ID) == 0 {
+	if to.ID == "" {
 		panic("bug: cannot restart empty folder ID")
 	}
 	if to.ID != from.ID {

+ 2 - 2
lib/protocol/encryption.go

@@ -547,7 +547,7 @@ func slashify(s string) string {
 // deslashify removes slashes and encrypted file extensions from the string.
 // This is the inverse of slashify().
 func deslashify(s string) (string, error) {
-	if len(s) == 0 || !strings.HasPrefix(s[1:], encryptedDirExtension) {
+	if s == "" || !strings.HasPrefix(s[1:], encryptedDirExtension) {
 		return "", fmt.Errorf("invalid encrypted path: %q", s)
 	}
 	s = s[:1] + s[1+len(encryptedDirExtension):]
@@ -575,7 +575,7 @@ func IsEncryptedParent(pathComponents []string) bool {
 	} else if l == 0 {
 		return false
 	}
-	if len(pathComponents[0]) == 0 {
+	if pathComponents[0] == "" {
 		return false
 	}
 	if pathComponents[0][1:] != encryptedDirExtension {

+ 2 - 2
lib/scanner/walk_test.go

@@ -748,12 +748,12 @@ func TestStopWalk(t *testing.T) {
 		f := res.File
 		t.Log("Scanned", f)
 		if f.IsDirectory() {
-			if len(f.Name) == 0 || f.Permissions == 0 {
+			if f.Name == "" || f.Permissions == 0 {
 				t.Error("Bad directory entry", f)
 			}
 			dirs++
 		} else {
-			if len(f.Name) == 0 || len(f.Blocks) == 0 || f.Permissions == 0 {
+			if f.Name == "" || len(f.Blocks) == 0 || f.Permissions == 0 {
 				t.Error("Bad file entry", f)
 			}
 			files++

+ 1 - 1
lib/upnp/upnp.go

@@ -383,7 +383,7 @@ func getIGDServices(deviceUUID string, localIPAddress net.IP, rootURL string, de
 				l.Debugln(rootURL, "- no services of type", URN, " found on connection.")
 
 				for _, service := range services {
-					if len(service.ControlURL) == 0 {
+					if service.ControlURL == "" {
 						l.Infoln(rootURL+"- malformed", service.Type, "description: no control URL.")
 					} else {
 						u, _ := url.Parse(rootURL)

+ 1 - 1
lib/ur/contract/contract.go

@@ -410,7 +410,7 @@ func clear(v interface{}, since int) error {
 		tag := t.Field(i).Tag
 
 		v := tag.Get("since")
-		if len(v) == 0 {
+		if v == "" {
 			f.Set(reflect.Zero(f.Type()))
 			continue
 		}