From e47c9584c1d41126abc71d9af633af03659829f1 Mon Sep 17 00:00:00 2001 From: jguer Date: Wed, 8 Jul 2020 03:40:50 +0200 Subject: [PATCH] fix(format): gofumt files --- callbacks.go | 1 - download.go | 4 +-- install.go | 7 ++--- keys.go | 1 - keys_test.go | 24 +++++++++++------ main.go | 2 +- pkg/intrange/intrange_test.go | 49 +++++++++++++++++++++++------------ pkg/settings/parser_test.go | 31 +++++++++++++--------- print.go | 11 ++++---- vcs.go | 18 +++++++------ vcs_test.go | 3 --- 11 files changed, 90 insertions(+), 61 deletions(-) diff --git a/callbacks.go b/callbacks.go index 8414b7bc..c518f65a 100644 --- a/callbacks.go +++ b/callbacks.go @@ -62,7 +62,6 @@ func questionCallback(question alpm.QuestionAny) { reader := bufio.NewReader(os.Stdin) numberBuf, overflow, err := reader.ReadLine() - if err != nil { text.Errorln(err) break diff --git a/download.go b/download.go index d70329c3..9029c7ec 100644 --- a/download.go +++ b/download.go @@ -71,7 +71,7 @@ func gitHasDiff(path, name string) (bool, error) { // TODO: yay-next passes args through the header, use that to unify ABS and AUR func gitDownloadABS(url, path, name string) (bool, error) { - if err := os.MkdirAll(path, 0755); err != nil { + if err := os.MkdirAll(path, 0o755); err != nil { return false, err } @@ -147,7 +147,6 @@ func getPkgbuilds(pkgs []string, alpmHandle *alpm.Handle, force bool) error { pkgs = removeInvalidTargets(pkgs) aur, repo, err := packageSlices(pkgs, alpmHandle) - if err != nil { return err } @@ -317,5 +316,6 @@ func getPkgbuildsfromABS(pkgs []string, path string, alpmHandle *alpm.Handle, fo } wg.Wait() + return len(missing) != 0, errs.Return() } diff --git a/install.go b/install.go index 4eaa02eb..be60b2e9 100644 --- a/install.go +++ b/install.go @@ -513,7 +513,6 @@ nextpkg: func parsePackageList(dir string) (pkgdests map[string]string, pkgVersion string, err error) { stdout, stderr, err := capture(passToMakepkg(dir, "--packagelist")) - if err != nil { return nil, "", fmt.Errorf("%s %s", stderr, err) } @@ -772,9 +771,11 @@ func showPkgbuildDiffs(bases []Base, cloned stringset.StringSet) error { } } - args := []string{"diff", + args := []string{ + "diff", start + "..HEAD@{upstream}", "--src-prefix", - dir + "/", "--dst-prefix", dir + "/", "--", ".", ":(exclude).SRCINFO"} + dir + "/", "--dst-prefix", dir + "/", "--", ".", ":(exclude).SRCINFO", + } if text.UseColor { args = append(args, "--color=always") } else { diff --git a/keys.go b/keys.go index dfaf1a23..13d2a4f7 100644 --- a/keys.go +++ b/keys.go @@ -96,7 +96,6 @@ func importKeys(keys []string) error { text.OperationInfoln(gotext.Get("Importing keys with gpg...")) err := cmd.Run() - if err != nil { return errors.New(gotext.Get("problem importing keys")) } diff --git a/keys_test.go b/keys_test.go index a30667d6..e14ca34a 100644 --- a/keys_test.go +++ b/keys_test.go @@ -100,8 +100,10 @@ func TestImportKeys(t *testing.T) { // 11E521D646982372EB577A1F8F0871F202119294: Tom Stellard. // B6C8F98282B944E3B0D5C2530FC3042E345AD05D: Hans Wennborg. { - keys: []string{"11E521D646982372EB577A1F8F0871F202119294", - "B6C8F98282B944E3B0D5C2530FC3042E345AD05D"}, + keys: []string{ + "11E521D646982372EB577A1F8F0871F202119294", + "B6C8F98282B944E3B0D5C2530FC3042E345AD05D", + }, wantError: false, }, // Single invalid key, should fail. @@ -117,8 +119,10 @@ func TestImportKeys(t *testing.T) { // Invalid + valid key. Should fail as well. // 647F28654894E3BD457199BE38DBBDC86092693E: Greg Kroah-Hartman. { - keys: []string{"THIS-SHOULD-FAIL", - "647F28654894E3BD457199BE38DBBDC86092693E"}, + keys: []string{ + "THIS-SHOULD-FAIL", + "647F28654894E3BD457199BE38DBBDC86092693E", + }, wantError: true, }, } @@ -182,7 +186,8 @@ func TestCheckPgpKeys(t *testing.T) { { pkgs: Base{newPkg("libc++")}, srcinfos: map[string]*gosrc.Srcinfo{ - "libc++": makeSrcinfo("libc++", "11E521D646982372EB577A1F8F0871F202119294", "B6C8F98282B944E3B0D5C2530FC3042E345AD05D")}, + "libc++": makeSrcinfo("libc++", "11E521D646982372EB577A1F8F0871F202119294", "B6C8F98282B944E3B0D5C2530FC3042E345AD05D"), + }, wantError: false, }, // Two dummy packages requiring the same key. @@ -192,7 +197,8 @@ func TestCheckPgpKeys(t *testing.T) { srcinfos: map[string]*gosrc.Srcinfo{ "dummy-1": makeSrcinfo("dummy-1", "ABAF11C65A2970B130ABE3C479BE3E4300411886"), - "dummy-2": makeSrcinfo("dummy-2", "ABAF11C65A2970B130ABE3C479BE3E4300411886")}, + "dummy-2": makeSrcinfo("dummy-2", "ABAF11C65A2970B130ABE3C479BE3E4300411886"), + }, wantError: false, }, // dummy package: single package, two valid keys, one of them already @@ -202,7 +208,8 @@ func TestCheckPgpKeys(t *testing.T) { { pkgs: Base{newPkg("dummy-3")}, srcinfos: map[string]*gosrc.Srcinfo{ - "dummy-3": makeSrcinfo("dummy-3", "11E521D646982372EB577A1F8F0871F202119294", "C52048C0C0748FEE227D47A2702353E0F7E48EDB")}, + "dummy-3": makeSrcinfo("dummy-3", "11E521D646982372EB577A1F8F0871F202119294", "C52048C0C0748FEE227D47A2702353E0F7E48EDB"), + }, wantError: false, }, // Two dummy packages with existing keys. @@ -210,7 +217,8 @@ func TestCheckPgpKeys(t *testing.T) { pkgs: Base{newPkg("dummy-4"), newPkg("dummy-5")}, srcinfos: map[string]*gosrc.Srcinfo{ "dummy-4": makeSrcinfo("dummy-4", "11E521D646982372EB577A1F8F0871F202119294"), - "dummy-5": makeSrcinfo("dummy-5", "C52048C0C0748FEE227D47A2702353E0F7E48EDB")}, + "dummy-5": makeSrcinfo("dummy-5", "C52048C0C0748FEE227D47A2702353E0F7E48EDB"), + }, wantError: false, }, // Dummy package with invalid key, should fail. diff --git a/main.go b/main.go index 05ff5882..318d548b 100644 --- a/main.go +++ b/main.go @@ -64,7 +64,7 @@ func initVCS(vcsFilePath string) error { func initBuildDir() error { if _, err := os.Stat(config.BuildDir); os.IsNotExist(err) { - if err = os.MkdirAll(config.BuildDir, 0755); err != nil { + if err = os.MkdirAll(config.BuildDir, 0o755); err != nil { return errors.New(gotext.Get("failed to create BuildDir directory '%s': %s", config.BuildDir, err)) } } else if err != nil { diff --git a/pkg/intrange/intrange_test.go b/pkg/intrange/intrange_test.go index f5c7cae9..78fe1752 100644 --- a/pkg/intrange/intrange_test.go +++ b/pkg/intrange/intrange_test.go @@ -30,39 +30,55 @@ func TestParseNumberMenu(t *testing.T) { } expected := []result{ - {IntRanges{makeIntRange(1, 1), + {IntRanges{ + makeIntRange(1, 1), makeIntRange(2, 2), makeIntRange(3, 3), makeIntRange(4, 4), - makeIntRange(5, 5)}, IntRanges{}, make(stringset.StringSet), make(stringset.StringSet)}, - {IntRanges{makeIntRange(1, 10), - makeIntRange(5, 15)}, IntRanges{}, make(stringset.StringSet), make(stringset.StringSet)}, - {IntRanges{makeIntRange(5, 10), - makeIntRange(85, 90)}, IntRanges{}, make(stringset.StringSet), make(stringset.StringSet)}, - {IntRanges{makeIntRange(1, 1), - makeIntRange(99, 99), - makeIntRange(60, 62)}, - IntRanges{makeIntRange(2, 2), + makeIntRange(5, 5), + }, IntRanges{}, make(stringset.StringSet), make(stringset.StringSet)}, + {IntRanges{ + makeIntRange(1, 10), + makeIntRange(5, 15), + }, IntRanges{}, make(stringset.StringSet), make(stringset.StringSet)}, + {IntRanges{ + makeIntRange(5, 10), + makeIntRange(85, 90), + }, IntRanges{}, make(stringset.StringSet), make(stringset.StringSet)}, + { + IntRanges{ + makeIntRange(1, 1), + makeIntRange(99, 99), + makeIntRange(60, 62), + }, + IntRanges{ + makeIntRange(2, 2), makeIntRange(5, 10), makeIntRange(38, 40), - makeIntRange(123, 123)}, - make(stringset.StringSet), make(stringset.StringSet)}, + makeIntRange(123, 123), + }, + make(stringset.StringSet), make(stringset.StringSet), + }, {IntRanges{}, IntRanges{}, stringset.Make("abort", "all", "none"), make(stringset.StringSet)}, {IntRanges{}, IntRanges{}, stringset.Make("a-b"), stringset.Make("abort", "a-b")}, {IntRanges{}, IntRanges{}, stringset.Make("-9223372036854775809-9223372036854775809"), make(stringset.StringSet)}, - {IntRanges{makeIntRange(1, 1), + {IntRanges{ + makeIntRange(1, 1), makeIntRange(2, 2), makeIntRange(3, 3), makeIntRange(4, 4), - makeIntRange(5, 5)}, IntRanges{}, make(stringset.StringSet), make(stringset.StringSet)}, - {IntRanges{makeIntRange(1, 1), + makeIntRange(5, 5), + }, IntRanges{}, make(stringset.StringSet), make(stringset.StringSet)}, + {IntRanges{ + makeIntRange(1, 1), makeIntRange(2, 2), makeIntRange(3, 3), makeIntRange(4, 4), makeIntRange(5, 5), makeIntRange(6, 6), makeIntRange(7, 7), - makeIntRange(8, 8)}, IntRanges{}, make(stringset.StringSet), make(stringset.StringSet)}, + makeIntRange(8, 8), + }, IntRanges{}, make(stringset.StringSet), make(stringset.StringSet)}, {IntRanges{}, IntRanges{}, make(stringset.StringSet), make(stringset.StringSet)}, {IntRanges{}, IntRanges{}, make(stringset.StringSet), make(stringset.StringSet)}, {IntRanges{}, IntRanges{}, stringset.Make("a", "b", "c", "d", "e"), make(stringset.StringSet)}, @@ -76,7 +92,6 @@ func TestParseNumberMenu(t *testing.T) { !intRangesEqual(exclude, res.Exclude) || !stringset.Equal(otherInclude, res.OtherInclude) || !stringset.Equal(otherExclude, res.OtherExclude) { - t.Fatalf("Test %d Failed: Expected: include=%+v exclude=%+v otherInclude=%+v otherExclude=%+v got include=%+v excluive=%+v otherInclude=%+v otherExclude=%+v", n+1, res.Include, res.Exclude, res.OtherInclude, res.OtherExclude, include, exclude, otherInclude, otherExclude) } diff --git a/pkg/settings/parser_test.go b/pkg/settings/parser_test.go index 48000b37..7ff35b55 100644 --- a/pkg/settings/parser_test.go +++ b/pkg/settings/parser_test.go @@ -123,16 +123,20 @@ func TestArguments_CopyGlobal(t *testing.T) { }{ {name: "simple", fields: fields{ Op: "Q", - Options: map[string]*Option{"a": {}, "arch": {Global: true, - Args: []string{"x86_x64"}, - }, "boo": {Global: true, Args: []string{"a", "b"}}, + Options: map[string]*Option{ + "a": {}, "arch": { + Global: true, + Args: []string{"x86_x64"}, + }, "boo": {Global: true, Args: []string{"a", "b"}}, }, Targets: []string{"a", "b"}, }, want: &Arguments{ Op: "", - Options: map[string]*Option{"arch": {Global: true, - Args: []string{"x86_x64"}, - }, "boo": {Global: true, Args: []string{"a", "b"}}, + Options: map[string]*Option{ + "arch": { + Global: true, + Args: []string{"x86_x64"}, + }, "boo": {Global: true, Args: []string{"a", "b"}}, }, Targets: []string{}, }}, @@ -166,16 +170,19 @@ func TestArguments_Copy(t *testing.T) { }{ {name: "simple", fields: fields{ Op: "Q", - Options: map[string]*Option{"a": {}, "arch": { - Args: []string{"x86_x64"}, Global: true, - }, "boo": {Args: []string{"a", "b"}, Global: true}, + Options: map[string]*Option{ + "a": {}, "arch": { + Args: []string{"x86_x64"}, Global: true, + }, "boo": {Args: []string{"a", "b"}, Global: true}, }, Targets: []string{"a", "b"}, }, want: &Arguments{ Op: "Q", - Options: map[string]*Option{"a": {}, "arch": {Global: true, - Args: []string{"x86_x64"}, - }, "boo": {Args: []string{"a", "b"}, Global: true}, + Options: map[string]*Option{ + "a": {}, "arch": { + Global: true, + Args: []string{"x86_x64"}, + }, "boo": {Args: []string{"a", "b"}, Global: true}, }, Targets: []string{"a", "b"}, }}, diff --git a/print.go b/print.go index 9383d6dd..26fe02a2 100644 --- a/print.go +++ b/print.go @@ -19,8 +19,10 @@ import ( "github.com/Jguer/yay/v10/pkg/text" ) -const arrow = "==>" -const smallArrow = " ->" +const ( + arrow = "==>" + smallArrow = " ->" +) func (warnings *aurWarnings) print() { if len(warnings.Missing) > 0 { @@ -353,7 +355,7 @@ func localStatistics(alpmHandle *alpm.Handle) error { return nil } -//TODO: Make it less hacky +// TODO: Make it less hacky func printNumberOfUpdates(alpmHandle *alpm.Handle, enableDowngrade bool) error { warnings := makeWarnings() old := os.Stdout // keep backup of the real stdout @@ -368,7 +370,7 @@ func printNumberOfUpdates(alpmHandle *alpm.Handle, enableDowngrade bool) error { return nil } -//TODO: Make it less hacky +// TODO: Make it less hacky func printUpdateList(cmdArgs *settings.Arguments, alpmHandle *alpm.Handle, enableDowngrade bool) error { targets := stringset.FromSlice(cmdArgs.Targets) warnings := makeWarnings() @@ -513,7 +515,6 @@ func providerMenu(dep string, providers providers) *rpc.Pkg { reader := bufio.NewReader(os.Stdin) numberBuf, overflow, err := reader.ReadLine() - if err != nil { fmt.Fprintln(os.Stderr, err) break diff --git a/vcs.go b/vcs.go index af45b327..efffe8a4 100644 --- a/vcs.go +++ b/vcs.go @@ -20,13 +20,15 @@ import ( ) // Info contains the last commit sha of a repo -type vcsInfo map[string]shaInfos -type shaInfos map[string]shaInfo -type shaInfo struct { - Protocols []string `json:"protocols"` - Branch string `json:"branch"` - SHA string `json:"sha"` -} +type ( + vcsInfo map[string]shaInfos + shaInfos map[string]shaInfo + shaInfo struct { + Protocols []string `json:"protocols"` + Branch string `json:"branch"` + SHA string `json:"sha"` + } +) // createDevelDB forces yay to create a DB of the existing development packages func createDevelDB(vcsFilePath string, alpmHandle *alpm.Handle) error { @@ -245,7 +247,7 @@ func saveVCSInfo(vcsFilePath string) error { if err != nil || string(marshalledinfo) == "null" { return err } - in, err := os.OpenFile(vcsFilePath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644) + in, err := os.OpenFile(vcsFilePath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0o644) if err != nil { return err } diff --git a/vcs_test.go b/vcs_test.go index 48baf350..b963e8c7 100644 --- a/vcs_test.go +++ b/vcs_test.go @@ -5,7 +5,6 @@ import ( ) func isEqual(a, b []string) bool { - if a == nil && b == nil { return true } @@ -59,10 +58,8 @@ func TestParsing(t *testing.T) { if url != compare.URL || branch != compare.Branch || !isEqual(protocols, compare.Protocols) { - t.Fatalf("Test %d failed: Expected: url=%+v branch=%+v protocols=%+v\ngot url=%+v branch=%+v protocols=%+v", n+1, compare.URL, compare.Branch, compare.Protocols, url, branch, protocols) } } - }