From d0782d6b1faaa7f29d80466876cea34e40579389 Mon Sep 17 00:00:00 2001 From: Dean Sheather Date: Tue, 8 Aug 2023 12:15:31 +0000 Subject: [PATCH 1/2] chore: fix ruleguard xerrors rules --- cli/stat.go | 2 +- scripts/rules.go | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/cli/stat.go b/cli/stat.go index 3657a4f3c71c9..6fb24b1fb6442 100644 --- a/cli/stat.go +++ b/cli/stat.go @@ -241,7 +241,7 @@ func (*RootCmd) statDisk(s *clistat.Statter) *clibase.Cmd { if err != nil { if os.IsNotExist(err) { // fmt.Errorf produces a more concise error. - return fmt.Errorf("not found: %q", pathArg) + return xerrors.Errorf("not found: %q", pathArg) } return err } diff --git a/scripts/rules.go b/scripts/rules.go index 20d0c43f7b883..1c26b80704b62 100644 --- a/scripts/rules.go +++ b/scripts/rules.go @@ -51,8 +51,12 @@ func xerrors(m dsl.Matcher) { m.Import("fmt") m.Import("golang.org/x/xerrors") - m.Match("fmt.Errorf($*args)"). - Suggest("xerrors.New($args)"). + m.Match("fmt.Errorf($arg)"). + Suggest("xerrors.New($arg)"). + Report("Use xerrors to provide additional stacktrace information!") + + m.Match("fmt.Errorf($arg1, $*args)"). + Suggest("xerrors.Errorf($arg1, $args)"). Report("Use xerrors to provide additional stacktrace information!") m.Match("errors.$_($msg)"). From afb11e2c7e48c1cd141405d99f3ae8adba6e4e78 Mon Sep 17 00:00:00 2001 From: Dean Sheather Date: Tue, 8 Aug 2023 12:18:15 +0000 Subject: [PATCH 2/2] fixup! chore: fix ruleguard xerrors rules --- cli/stat.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cli/stat.go b/cli/stat.go index 6fb24b1fb6442..6311596ecea2a 100644 --- a/cli/stat.go +++ b/cli/stat.go @@ -240,8 +240,8 @@ func (*RootCmd) statDisk(s *clistat.Statter) *clibase.Cmd { ds, err := s.Disk(pfx, pathArg) if err != nil { if os.IsNotExist(err) { - // fmt.Errorf produces a more concise error. - return xerrors.Errorf("not found: %q", pathArg) + //nolint:gocritic // fmt.Errorf produces a more concise error. + return fmt.Errorf("not found: %q", pathArg) } return err }