1
0
mirror of https://github.com/mgechev/revive.git synced 2024-11-24 08:32:22 +02:00

Move away from deprecated github.com/pkg/errors (#1039)

This commit is contained in:
Oleksandr Redko 2024-09-16 10:40:46 +03:00 committed by GitHub
parent 6b745b0075
commit 59131927d3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 10 additions and 14 deletions

1
go.mod
View File

@ -11,7 +11,6 @@ require (
github.com/mgechev/dots v0.0.0-20210922191527-e955255bf517
github.com/mitchellh/go-homedir v1.1.0
github.com/olekukonko/tablewriter v0.0.5
github.com/pkg/errors v0.9.1
github.com/spf13/afero v1.11.0
golang.org/x/mod v0.20.0
golang.org/x/tools v0.24.0

2
go.sum
View File

@ -24,8 +24,6 @@ github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
github.com/olekukonko/tablewriter v0.0.5/go.mod h1:hPp6KlRPjbx+hW8ykQs1w3UBbZlj6HuIJcUGPhkA7kY=
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/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8=

View File

@ -2,6 +2,7 @@
package revivelib
import (
"fmt"
"log"
"os"
"strings"
@ -10,7 +11,6 @@ import (
"github.com/mgechev/revive/config"
"github.com/mgechev/revive/lint"
"github.com/mgechev/revive/logging"
"github.com/pkg/errors"
)
// Revive is responsible for running linters and formatters
@ -31,7 +31,7 @@ func New(
) (*Revive, error) {
logger, err := logging.GetLogger()
if err != nil {
return nil, errors.Wrap(err, "initializing revive - getting logger")
return nil, fmt.Errorf("initializing revive - getting logger: %w", err)
}
if setExitStatus {
@ -53,7 +53,7 @@ func New(
lintingRules, err := config.GetLintingRules(conf, extraRuleInstances)
if err != nil {
return nil, errors.Wrap(err, "initializing revive - getting lint rules")
return nil, fmt.Errorf("initializing revive - getting lint rules: %w", err)
}
logger.Println("Config loaded")
@ -85,14 +85,14 @@ func (r *Revive) Lint(patterns ...*LintPattern) (<-chan lint.Failure, error) {
packages, err := getPackages(includePatterns, excludePatterns)
if err != nil {
return nil, errors.Wrap(err, "linting - getting packages")
return nil, fmt.Errorf("linting - getting packages: %w", err)
}
revive := lint.New(func(file string) ([]byte, error) {
contents, err := os.ReadFile(file)
if err != nil {
return nil, errors.Wrap(err, "reading file "+file)
return nil, fmt.Errorf("reading file %v: %w", file, err)
}
return contents, nil
@ -100,7 +100,7 @@ func (r *Revive) Lint(patterns ...*LintPattern) (<-chan lint.Failure, error) {
failures, err := revive.Lint(packages, r.lintingRules, *r.config)
if err != nil {
return nil, errors.Wrap(err, "linting - retrieving failures channel")
return nil, fmt.Errorf("linting - retrieving failures channel: %w", err)
}
return failures, nil
@ -117,7 +117,7 @@ func (r *Revive) Format(
formatter, err := config.GetFormatter(formatterName)
if err != nil {
return "", 0, errors.Wrap(err, "formatting - getting formatter")
return "", 0, fmt.Errorf("formatting - getting formatter: %w", err)
}
var (
@ -157,7 +157,7 @@ func (r *Revive) Format(
<-exitChan
if formatErr != nil {
return "", exitCode, errors.Wrap(err, "formatting")
return "", exitCode, fmt.Errorf("formatting: %w", err)
}
return output, exitCode, nil
@ -171,7 +171,7 @@ func getPackages(includePatterns []string, excludePatterns ArrayFlags) ([][]stri
packages, err := dots.ResolvePackages(globs, normalizeSplit(excludePatterns))
if err != nil {
return nil, errors.Wrap(err, "getting packages - resolving packages in dots")
return nil, fmt.Errorf("getting packages - resolving packages in dots: %w", err)
}
return packages, nil

View File

@ -15,7 +15,6 @@ import (
"testing"
"github.com/mgechev/revive/lint"
"github.com/pkg/errors"
)
func testRule(t *testing.T, filename string, rule lint.Rule, config ...*lint.RuleConfig) {
@ -69,7 +68,7 @@ func assertFailures(t *testing.T, baseDir string, fi os.FileInfo, src []byte, ru
ins := parseInstructions(t, fi.Name(), src)
if ins == nil {
return errors.Errorf("Test file %v does not have instructions", fi.Name())
return fmt.Errorf("Test file %v does not have instructions", fi.Name())
}
ps, err := l.Lint([][]string{{fi.Name()}}, rules, lint.Config{