Skip to content

Commit

Permalink
Remove deprecated pkg errors (#28)
Browse files Browse the repository at this point in the history
Replace github.com/pkg/errors with native error handling

pkg/errors has been deprecated since go1.13.
Let's also set go1.13 as the new minimum.

---------

Co-authored-by: Oleksandr Redko <oleksandr.red+github@gmail.com>
  • Loading branch information
ashanbrown and alexandear committed Feb 25, 2023
1 parent 7298305 commit 2a92cc5
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 12 deletions.
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,11 @@ isn't necessary. The following pattern strings are equivalent:
A larger set of interesting patterns might include:

-* `^fmt\.Print.*$` -- forbid use of Print statements because they are likely just for debugging
-* `^fmt\.Errorf$` -- forbid Errorf in favor of using github.com/pkg/errors
-* `^ginkgo\.F[A-Z].*$` -- forbid ginkgo focused commands (used for debug issues)
-* `^spew\.Dump$` -- forbid dumping detailed data to stdout
-* `^spew.ConfigState\.Dump$` -- also forbid it via a `ConfigState`
-* `^fmt\.Errorf(# please use github\.com/pkg/errors)?$` -- forbid Errorf, with a custom message
-* `{p: ^fmt\.Errorf$, msg: please use github.com/pkg/errors}` -- the same with separate msg field
-* `^spew\.Dump(# please do not spew to stdout)?$` -- forbid spewing, with a custom message
-* `{p: ^spew\.Dump$, msg: please do not spew to stdout}` -- the same with separate msg field

### Flags
- **-set_exit_status** (default false) - Set exit status to 1 if any issues are found.
Expand Down
4 changes: 1 addition & 3 deletions forbidigo/forbidigo.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
"log"
"regexp"
"strings"

"github.com/pkg/errors"
)

type Issue interface {
Expand Down Expand Up @@ -72,7 +70,7 @@ type config struct {
func NewLinter(patterns []string, options ...Option) (*Linter, error) {
cfg, err := newConfig(options...)
if err != nil {
return nil, errors.Wrapf(err, "failed to process options")
return nil, fmt.Errorf("failed to process options: %w", err)
}

if len(patterns) == 0 {
Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
module github.com/ashanbrown/forbidigo

go 1.12
go 1.13

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/google/go-cmp v0.5.6
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.5.1
golang.org/x/sys v0.5.0 // indirect
golang.org/x/tools v0.3.0
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/go-cmp v0.5.6 h1:BKbKCqvP6I+rmFHt06ZmyQtvB8xAkWdhFyr0ZUNZcxQ=
github.com/google/go-cmp v0.5.6/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand Down
5 changes: 3 additions & 2 deletions pkg/analyzer/analyzer.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package analyzer

import (
"errors"
"flag"
"fmt"
"go/ast"

"github.com/ashanbrown/forbidigo/forbidigo"
"github.com/pkg/errors"
"golang.org/x/tools/go/analysis"
)

Expand Down Expand Up @@ -71,7 +72,7 @@ func (a *analyzer) runAnalysis(pass *analysis.Pass) (interface{}, error) {
forbidigo.OptionAnalyzeTypes(a.analyzeTypes),
)
if err != nil {
return nil, errors.Wrapf(err, "failed to configure linter")
return nil, fmt.Errorf("failed to configure linter: %w", err)
}
nodes := make([]ast.Node, 0, len(pass.Files))
for _, f := range pass.Files {
Expand Down

0 comments on commit 2a92cc5

Please sign in to comment.