[lxc-devel] [lxd/master] Fixes to code quality

de-sh on Github lxc-bot at linuxcontainers.org
Mon Dec 14 14:32:51 UTC 2020


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 851 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20201214/411a6322/attachment.bin>
-------------- next part --------------
From c731e3e5ae3af292f15aa7e6e9cf8425a715c813 Mon Sep 17 00:00:00 2001
From: Devdutt Shenoi <devdutt at outlook.in>
Date: Sat, 12 Dec 2020 21:54:56 +0530
Subject: [PATCH 1/5] Add DeepSource config

Signed-off-by: Devdutt Shenoi <devdutt at outlook.in>
---
 .deepsource.toml | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
 create mode 100644 .deepsource.toml

diff --git a/.deepsource.toml b/.deepsource.toml
new file mode 100644
index 0000000000..8588c35be6
--- /dev/null
+++ b/.deepsource.toml
@@ -0,0 +1,20 @@
+version = 1
+
+test_patterns = [
+    "test/**",
+    "*_test.go"
+]
+
+[[analyzers]]
+name = "python"
+enabled = true
+
+  [analyzers.meta]
+  runtime_version = "3.x.x"
+
+[[analyzers]]
+name = "go"
+enabled = true
+
+  [analyzers.meta]
+  import_paths = ["github.com/lxd/lxd"]
\ No newline at end of file

From 8d6f3f891766ee0b41eee498d5be9cc22adf7c31 Mon Sep 17 00:00:00 2001
From: Devdutt Shenoi <devdutt at outlook.in>
Date: Sat, 12 Dec 2020 21:55:56 +0530
Subject: [PATCH 2/5] Use result of type assertion to simplify cases

Signed-off-by: Devdutt Shenoi <devdutt at outlook.in>
---
 client/lxd.go | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/client/lxd.go b/client/lxd.go
index 220f7bc900..77ec3e80f7 100644
--- a/client/lxd.go
+++ b/client/lxd.go
@@ -179,10 +179,10 @@ func (r *ProtocolLXD) rawQuery(method string, url string, data interface{}, ETag
 
 	// Get a new HTTP request setup
 	if data != nil {
-		switch data.(type) {
+		switch data := data.(type) {
 		case io.Reader:
 			// Some data to be sent along with the request
-			req, err = http.NewRequest(method, url, data.(io.Reader))
+			req, err = http.NewRequest(method, url, data)
 			if err != nil {
 				return nil, "", err
 			}

From 584599931a5759911c1a9226b2ea8a64199b543a Mon Sep 17 00:00:00 2001
From: Devdutt Shenoi <devdutt at outlook.in>
Date: Sat, 12 Dec 2020 21:56:28 +0530
Subject: [PATCH 3/5] Replace .Sub(time.Now()) with time.Until() handler

Signed-off-by: Devdutt Shenoi <devdutt at outlook.in>
---
 lxc/utils/progress.go | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lxc/utils/progress.go b/lxc/utils/progress.go
index 1a548d7539..815354f2bb 100644
--- a/lxc/utils/progress.go
+++ b/lxc/utils/progress.go
@@ -83,7 +83,7 @@ func (p *ProgressRenderer) Done(msg string) {
 // Update changes the status message to the provided string
 func (p *ProgressRenderer) Update(status string) {
 	// Wait if needed
-	timeout := p.wait.Sub(time.Now())
+	timeout := time.Until(p.wait)
 	if timeout.Seconds() > 0 {
 		time.Sleep(timeout)
 	}

From 07828469f9c6520ef07a48905483832c6fcec495 Mon Sep 17 00:00:00 2001
From: Devdutt Shenoi <devdutt at outlook.in>
Date: Sat, 12 Dec 2020 21:56:58 +0530
Subject: [PATCH 4/5] Remove unnecessary fmt.Sprintf() on string

Signed-off-by: Devdutt Shenoi <devdutt at outlook.in>
---
 lxc/query.go          | 2 +-
 lxc/utils/progress.go | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/lxc/query.go b/lxc/query.go
index 29e58de88a..498b93d9cb 100644
--- a/lxc/query.go
+++ b/lxc/query.go
@@ -55,7 +55,7 @@ func (c *cmdQuery) pretty(input interface{}) string {
 		return fmt.Sprintf("%v", input)
 	}
 
-	return fmt.Sprintf("%s", pretty.String())
+	return pretty.String()
 }
 
 func (c *cmdQuery) Run(cmd *cobra.Command, args []string) error {
diff --git a/lxc/utils/progress.go b/lxc/utils/progress.go
index 815354f2bb..9b7ef1892d 100644
--- a/lxc/utils/progress.go
+++ b/lxc/utils/progress.go
@@ -153,7 +153,7 @@ func (p *ProgressRenderer) Warn(status string, timeout time.Duration) {
 
 	// Render the new message
 	p.wait = time.Now().Add(timeout)
-	msg := fmt.Sprintf("%s", status)
+	msg := status
 
 	// Truncate msg to terminal length
 	msg = "\r" + p.truncate(msg)

From efd22b81c3741d0d30bae86ea9e6151371240bb1 Mon Sep 17 00:00:00 2001
From: Devdutt Shenoi <devdutt at outlook.in>
Date: Sat, 12 Dec 2020 21:57:31 +0530
Subject: [PATCH 5/5] Omit comparison with boolean constant

Signed-off-by: Devdutt Shenoi <devdutt at outlook.in>
---
 lxc/delete.go | 2 +-
 lxc/image.go  | 2 +-
 lxc/list.go   | 4 ++--
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/lxc/delete.go b/lxc/delete.go
index 5aad5dfe4c..7d8af77a2a 100644
--- a/lxc/delete.go
+++ b/lxc/delete.go
@@ -121,7 +121,7 @@ func (c *cmdDelete) Run(cmd *cobra.Command, args []string) error {
 				return fmt.Errorf(i18n.G("Stopping the instance failed: %s"), err)
 			}
 
-			if ct.Ephemeral == true {
+			if ct.Ephemeral {
 				return nil
 			}
 		}
diff --git a/lxc/image.go b/lxc/image.go
index 1d1900174f..8d3332ac53 100644
--- a/lxc/image.go
+++ b/lxc/image.go
@@ -1151,7 +1151,7 @@ func (c *cmdImageList) imageShouldShow(filters []string, state *api.Image) bool
 							found = true
 							break
 						}
-					} else if r.MatchString(configValue) == true {
+					} else if r.MatchString(configValue) {
 						found = true
 						break
 					}
diff --git a/lxc/list.go b/lxc/list.go
index e5aea95301..00281c5667 100644
--- a/lxc/list.go
+++ b/lxc/list.go
@@ -176,7 +176,7 @@ func (c *cmdList) shouldShow(filters []string, state *api.Instance) bool {
 							// the property was found but didn't match
 							return false
 						}
-					} else if r.MatchString(configValue) == true {
+					} else if r.MatchString(configValue) {
 						found = true
 						break
 					}
@@ -197,7 +197,7 @@ func (c *cmdList) shouldShow(filters []string, state *api.Instance) bool {
 			}
 
 			r, err := regexp.Compile(regexpValue)
-			if err == nil && r.MatchString(state.Name) == true {
+			if err == nil && r.MatchString(state.Name) {
 				continue
 			}
 


More information about the lxc-devel mailing list