Skip to content

Commit 50cf3ad

Browse files
committed
Fix staticcheck warnings
Signed-off-by: xplshn <xplshn@murena.io>
1 parent 91132cc commit 50cf3ad

File tree

4 files changed

+7
-55
lines changed

4 files changed

+7
-55
lines changed

main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func main() {
5656

5757
err := app.Run(context.Background(), os.Args)
5858
if err != nil {
59-
fmt.Fprintf(os.Stderr, "%v", err)
59+
fmt.Fprintf(os.Stderr, "%v\n", err)
6060
os.Exit(1)
6161
}
6262
}

search.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ func fSearch(config *Config, searchTerms []string, uRepoIndex []binaryEntry) err
5656
}
5757

5858
if len(results) == 0 {
59-
return fmt.Errorf("no matching binaries found for '%s'\n",
59+
return fmt.Errorf("no matching binaries found for '%s'",
6060
strings.Join(searchTerms, " "))
6161
} else if uint(len(results)) > config.Limit {
62-
return fmt.Errorf("too many matching binaries (+%d. [Use --limit before your query]) found for '%s'\n",
62+
return fmt.Errorf("too many matching binaries (+%d. [Use --limit before your query]) found for '%s'",
6363
config.Limit, strings.Join(searchTerms, " "))
6464
}
6565

update.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ func update(config *Config, programsToUpdate []binaryEntry, verbosityLevel Verbo
146146
}
147147

148148
if verbosityLevel >= normalVerbosity || (errors > 0 && verbosityLevel >= silentVerbosityWithErrors) {
149-
fmt.Printf(finalCounts)
149+
fmt.Print(finalCounts)
150150
for _, errorMsg := range strings.Split(errorMessages, "\n") {
151151
fmt.Println(strings.TrimSpace(errorMsg))
152152
}

utility.go

+3-51
Original file line numberDiff line numberDiff line change
@@ -22,43 +22,11 @@ import (
2222
"github.com/zeebo/blake3"
2323
)
2424

25-
func removeDuplicates[T comparable](elements []T) []T {
26-
seen := make(map[T]struct{})
27-
result := []T{}
28-
for _, element := range elements {
29-
if _, ok := seen[element]; !ok {
30-
seen[element] = struct{}{}
31-
result = append(result, element)
32-
}
33-
}
34-
return result
35-
}
36-
37-
func contains(slice []string, str string) bool {
38-
for _, v := range slice {
39-
if v == str {
40-
return true
41-
}
42-
}
43-
return false
44-
}
45-
4625
func fileExists(filePath string) bool {
4726
_, err := os.Stat(filePath)
4827
return !os.IsNotExist(err)
4928
}
5029

51-
func isDirectory(path string) (bool, error) {
52-
info, err := os.Stat(path)
53-
if err != nil {
54-
if os.IsNotExist(err) {
55-
return false, nil
56-
}
57-
return false, err
58-
}
59-
return info.IsDir(), nil
60-
}
61-
6230
func isExecutable(filePath string) bool {
6331
info, err := os.Stat(filePath)
6432
if err != nil {
@@ -178,22 +146,6 @@ func bEntryOfinstalledBinary(binaryPath string) binaryEntry {
178146
return trackedBEntry
179147
}
180148

181-
func errorEncoder(format string, args ...interface{}) int {
182-
formattedErrorMessage := fmt.Sprintf(format, args...)
183-
184-
var sum int
185-
for _, char := range formattedErrorMessage {
186-
sum += int(char)
187-
}
188-
errorCode := sum % 256
189-
fmt.Fprint(os.Stderr, formattedErrorMessage)
190-
return errorCode
191-
}
192-
193-
func errorOut(format string, args ...interface{}) {
194-
os.Exit(errorEncoder(format, args...))
195-
}
196-
197149
func getTerminalWidth() int {
198150
w, _, _ := term.GetSize(int(os.Stdout.Fd()))
199151
if w != 0 {
@@ -286,7 +238,7 @@ func embedBEntry(binaryPath string, bEntry binaryEntry) error {
286238

287239
func readEmbeddedBEntry(binaryPath string) (binaryEntry, error) {
288240
if !fileExists(binaryPath) {
289-
return binaryEntry{}, fmt.Errorf("Error: Tried to get EmbeddedBEntry of non-existant file: %s", binaryPath)
241+
return binaryEntry{}, fmt.Errorf("error: Tried to get EmbeddedBEntry of non-existant file: %s", binaryPath)
290242
}
291243

292244
fullName, err := xattr.Get(binaryPath, "user.FullName")
@@ -330,7 +282,7 @@ func removeNixGarbageFoundInTheRepos(filePath string) error {
330282

331283
func decodeRepoIndex(url string) ([]binaryEntry, error) {
332284
if url == "" {
333-
return nil, fmt.Errorf("repository index URL is empty. Please check your configuration or remove it.")
285+
return nil, fmt.Errorf("repository index URL is empty. Please check your configuration or remove it")
334286
}
335287

336288
req, err := http.NewRequest("GET", url, nil)
@@ -344,7 +296,7 @@ func decodeRepoIndex(url string) ([]binaryEntry, error) {
344296
client := &http.Client{}
345297
response, err := client.Do(req)
346298
if err != nil {
347-
return nil, fmt.Errorf("error fetching from %s: %v. Please check your configuration's repo_urls. Ensure your network has access to the internet.", url, err)
299+
return nil, fmt.Errorf("error fetching from %s: %v. Please check your configuration's repo_urls. Ensure your network has access to the internet", url, err)
348300
}
349301
defer response.Body.Close()
350302
bodyReader := response.Body

0 commit comments

Comments
 (0)