chore: resolve revive linter issues

Amolith and Crush created

Fix 2 superfluous-else issues in cmd/willow.go where if blocks end
with os.Exit calls, add comment justifying blank import in db/db.go,
and fix 2 var-naming issues in db/posthooks.go.

Co-Authored-By: Crush <crush@charm.land>

Change summary

cmd/willow.go   | 10 +++++-----
db/db.go        |  1 +
db/posthooks.go | 28 ++++++++++++++--------------
3 files changed, 20 insertions(+), 19 deletions(-)

Detailed changes

cmd/willow.go 🔗

@@ -143,10 +143,10 @@ func main() {
 	if err := httpServer.ListenAndServe(); errors.Is(err, http.ErrServerClosed) {
 		fmt.Println("Web server closed")
 		os.Exit(0)
-	} else {
-		fmt.Println(err)
-		os.Exit(1)
 	}
+
+	fmt.Println(err)
+	os.Exit(1)
 }
 
 func checkConfig() error {
@@ -181,9 +181,9 @@ Listen = "%s"`, defaultDBConn, defaultFetchInterval, defaultFetchInterval, defau
 			fmt.Println("Config file created at", *flagConfig)
 			fmt.Println("Please edit it and restart the server")
 			os.Exit(0)
-		} else {
-			return fmt.Errorf("failed to open config file: %w", err)
 		}
+
+		return fmt.Errorf("failed to open config file: %w", err)
 	}
 	defer file.Close()
 

db/db.go 🔗

@@ -11,6 +11,7 @@ import (
 	"fmt"
 	"sync"
 
+	// Import SQLite driver for database connectivity.
 	_ "modernc.org/sqlite"
 )
 

db/posthooks.go 🔗

@@ -25,17 +25,17 @@ func generateAndInsertProjectIDs(tx *sql.Tx) error {
 
 	for rows.Next() {
 		var (
-			url        string
-			name       string
-			forge      string
-			version    string
-			created_at string
+			url       string
+			name      string
+			forge     string
+			version   string
+			createdAt string
 		)
-		if err := rows.Scan(&url, &name, &forge, &version, &created_at); err != nil {
+		if err := rows.Scan(&url, &name, &forge, &version, &createdAt); err != nil {
 			return fmt.Errorf("failed to scan row from projects_tmp: %w", err)
 		}
 
-		id := fmt.Sprintf("%x", sha256.Sum256([]byte(url+name+forge+created_at)))
+		id := fmt.Sprintf("%x", sha256.Sum256([]byte(url+name+forge+createdAt)))
 
 		_, err = tx.Exec(
 			"INSERT INTO projects (id, url, name, forge, version, created_at) VALUES (@id, @url, @name, @forge, @version, @created_at)",
@@ -44,7 +44,7 @@ func generateAndInsertProjectIDs(tx *sql.Tx) error {
 			sql.Named("name", name),
 			sql.Named("forge", forge),
 			sql.Named("version", version),
-			sql.Named("created_at", created_at),
+			sql.Named("created_at", createdAt),
 		)
 		if err != nil {
 			return fmt.Errorf("failed to insert project into projects: %w", err)
@@ -72,12 +72,12 @@ func correctProjectIDs(tx *sql.Tx) error {
 
 	for rows.Next() {
 		var (
-			old_id string
-			url    string
-			name   string
-			forge  string
+			oldID string
+			url   string
+			name  string
+			forge string
 		)
-		if err := rows.Scan(&old_id, &url, &name, &forge); err != nil {
+		if err := rows.Scan(&oldID, &url, &name, &forge); err != nil {
 			return fmt.Errorf("failed to scan row from projects_tmp: %w", err)
 		}
 
@@ -86,7 +86,7 @@ func correctProjectIDs(tx *sql.Tx) error {
 		_, err = tx.Exec(
 			"UPDATE projects SET id = @id WHERE id = @old_id",
 			sql.Named("id", id),
-			sql.Named("old_id", old_id),
+			sql.Named("old_id", oldID),
 		)
 		if err != nil {
 			return fmt.Errorf("failed to insert project into projects: %w", err)