From d319576303938ad09caea6bb800c53ca5bf13a0d Mon Sep 17 00:00:00 2001 From: Jguer Date: Fri, 27 Apr 2018 01:25:40 +0100 Subject: [PATCH] Use megacheck to lint project Signed-off-by: Jguer --- download.go | 6 +----- keys_test.go | 9 +++------ parser.go | 6 +++--- parser_test.go | 2 +- print.go | 4 ++++ query.go | 2 +- upgrade.go | 4 ++-- vcs.go | 4 ---- 8 files changed, 15 insertions(+), 22 deletions(-) diff --git a/download.go b/download.go index 79f8a30d..0a932108 100644 --- a/download.go +++ b/download.go @@ -21,11 +21,7 @@ func shouldUseGit(path string) bool { } _, err = os.Stat(filepath.Join(path, ".git")) - if os.IsNotExist(err) { - return false - } - - return true + return os.IsExist(err) } func downloadFile(path string, url string) (err error) { diff --git a/keys_test.go b/keys_test.go index f42941b3..ab8e0560 100644 --- a/keys_test.go +++ b/keys_test.go @@ -2,6 +2,7 @@ package main import ( "bytes" + "context" "fmt" "io/ioutil" "net/http" @@ -36,10 +37,6 @@ func newPkg(basename string) *rpc.Pkg { return &rpc.Pkg{Name: basename, PackageBase: basename} } -func newSplitPkg(basename, name string) *rpc.Pkg { - return &rpc.Pkg{Name: name, PackageBase: basename} -} - func getPgpKey(key string) string { var buffer bytes.Buffer @@ -73,7 +70,7 @@ func TestImportKeys(t *testing.T) { config.GpgFlags = fmt.Sprintf("--homedir %s --keyserver 127.0.0.1", keyringDir) server := startPgpKeyServer() - defer server.Shutdown(nil) + defer server.Shutdown(context.TODO()) casetests := []struct { keys []string @@ -138,7 +135,7 @@ func TestCheckPgpKeys(t *testing.T) { config.GpgFlags = fmt.Sprintf("--homedir %s --keyserver 127.0.0.1", keyringDir) server := startPgpKeyServer() - defer server.Shutdown(nil) + defer server.Shutdown(context.TODO()) casetests := []struct { pkgs []*rpc.Pkg diff --git a/parser.go b/parser.go index 9957cb56..3d8199e4 100644 --- a/parser.go +++ b/parser.go @@ -220,7 +220,7 @@ func (parser *arguments) getArg(options ...string) (arg string, double bool, exi existCount := 0 for _, option := range options { - arg, exists = parser.options[option] + _, exists = parser.options[option] if exists { existCount++ @@ -619,8 +619,8 @@ func (parser *arguments) parseCommandLine() (err error) { //of course the implementation is up to the caller, this function mearley parses //the input and organizes it func parseNumberMenu(input string) (intRanges, intRanges, stringSet, stringSet) { - include := make(intRanges, 0, 0) - exclude := make(intRanges, 0, 0) + include := make(intRanges, 0) + exclude := make(intRanges, 0) otherInclude := make(stringSet) otherExclude := make(stringSet) diff --git a/parser_test.go b/parser_test.go index 47c05177..5aa57c67 100644 --- a/parser_test.go +++ b/parser_test.go @@ -19,7 +19,7 @@ func intRangesEqual(a, b intRanges) bool { r1 := a[n] r2 := b[n] - if r1.min != r1.min || r1.max != r2.max { + if r1.min != r2.min || r1.max != r2.max { return false } } diff --git a/print.go b/print.go index bb2873a8..293d1ef4 100644 --- a/print.go +++ b/print.go @@ -341,6 +341,10 @@ func printUpdateList(parser *arguments) error { old := os.Stdout // keep backup of the real stdout os.Stdout = nil _, _, localNames, remoteNames, err := filterPackages() + if err != nil { + return err + } + aurUp, repoUp, err := upList(warnings) os.Stdout = old // restoring the real stdout if err != nil { diff --git a/query.go b/query.go index 99dcfe20..3eb22f69 100644 --- a/query.go +++ b/query.go @@ -353,7 +353,7 @@ func hangingPackages(removeOptional bool) (hanging []string, err error) { iterateAgain := true processDependencies := func(pkg alpm.Package) error { - if state, _ := safePackages[pkg.Name()]; state == 0 || state == 2 { + if state := safePackages[pkg.Name()]; state == 0 || state == 2 { return nil } diff --git a/upgrade.go b/upgrade.go index f816d728..afa753e8 100644 --- a/upgrade.go +++ b/upgrade.go @@ -193,8 +193,8 @@ func upList(warnings *aurWarnings) (aurUp upSlice, repoUp upSlice, err error) { } func upDevel(remote []alpm.Package) (toUpgrade upSlice, err error) { - toUpdate := make([]alpm.Package, 0, 0) - toRemove := make([]string, 0, 0) + toUpdate := make([]alpm.Package, 0) + toRemove := make([]string, 0) var mux1 sync.Mutex var mux2 sync.Mutex diff --git a/vcs.go b/vcs.go index 9b120b7d..5b219c3c 100644 --- a/vcs.go +++ b/vcs.go @@ -205,10 +205,6 @@ func (infos shaInfos) needsUpdate() bool { } } -func inStore(pkgName string) shaInfos { - return savedInfo[pkgName] -} - func saveVCSInfo() error { marshalledinfo, err := json.MarshalIndent(savedInfo, "", "\t") if err != nil || string(marshalledinfo) == "null" {