Browse Source

all: replace empty slice literal with `var` (#8990)

refactor: replace empty slice literal with `var`

An empty slice can be represented by `nil` or an empty slice literal. They are
functionally equivalent — their `len` and `cap` are both zero — but the `nil`
slice is the preferred style. For more information about empty slices,
see [Declaring Empty Slices](https://github.com/golang/go/wiki/CodeReviewComments#declaring-empty-slices).

Co-authored-by: deepsource-autofix[bot] <62050782+deepsource-autofix[bot]@users.noreply.github.com>
deepsource-autofix[bot] 2 years ago
parent
commit
21c074cc2c
4 changed files with 8 additions and 4 deletions
  1. 2 1
      lib/model/model_test.go
  2. 2 1
      lib/osutil/net.go
  3. 2 1
      lib/versioner/empty_dir_tracker.go
  4. 2 1
      lib/versioner/external.go

+ 2 - 1
lib/model/model_test.go

@@ -1709,7 +1709,8 @@ func TestGlobalDirectoryTree(t *testing.T) {
 
 	b := func(isfile bool, path ...string) protocol.FileInfo {
 		typ := protocol.FileInfoTypeDirectory
-		blocks := []protocol.BlockInfo{}
+		var blocks []protocol.BlockInfo
+
 		if isfile {
 			typ = protocol.FileInfoTypeFile
 			blocks = []protocol.BlockInfo{{Offset: 0x0, Size: 0xa, Hash: []uint8{0x2f, 0x72, 0xcc, 0x11, 0xa6, 0xfc, 0xd0, 0x27, 0x1e, 0xce, 0xf8, 0xc6, 0x10, 0x56, 0xee, 0x1e, 0xb1, 0x24, 0x3b, 0xe3, 0x80, 0x5b, 0xf9, 0xa9, 0xdf, 0x98, 0xf9, 0x2f, 0x76, 0x36, 0xb0, 0x5c}}}

+ 2 - 1
lib/osutil/net.go

@@ -15,7 +15,8 @@ func GetLans() ([]*net.IPNet, error) {
 	if err != nil {
 		return nil, err
 	}
-	addrs := []net.Addr{}
+	var addrs []net.Addr
+
 	for _, currentIf := range ifs {
 		if currentIf.Flags&net.FlagUp != net.FlagUp {
 			continue

+ 2 - 1
lib/versioner/empty_dir_tracker.go

@@ -32,7 +32,8 @@ func (t emptyDirTracker) addFile(path string) {
 }
 
 func (t emptyDirTracker) emptyDirs() []string {
-	empty := []string{}
+	var empty []string
+
 	for dir := range t {
 		empty = append(empty, dir)
 	}

+ 2 - 1
lib/versioner/external.go

@@ -90,7 +90,8 @@ func (v external) Archive(filePath string) error {
 	cmd := exec.Command(words[0], words[1:]...)
 	env := os.Environ()
 	// filter STGUIAUTH and STGUIAPIKEY from environment variables
-	filteredEnv := []string{}
+	var filteredEnv []string
+
 	for _, x := range env {
 		if !strings.HasPrefix(x, "STGUIAUTH=") && !strings.HasPrefix(x, "STGUIAPIKEY=") {
 			filteredEnv = append(filteredEnv, x)