diff --git a/go.mod b/go.mod index 2c48d4b92..ca23cba6c 100644 --- a/go.mod +++ b/go.mod @@ -13,6 +13,7 @@ require ( github.com/olekukonko/tablewriter v0.0.5 github.com/spf13/afero v1.11.0 golang.org/x/mod v0.22.0 + golang.org/x/sync v0.10.0 golang.org/x/tools v0.28.0 ) diff --git a/go.sum b/go.sum index 1cd6350b3..696de223e 100644 --- a/go.sum +++ b/go.sum @@ -42,6 +42,8 @@ github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsT github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= golang.org/x/mod v0.22.0 h1:D4nJWe9zXqHOmWqj4VMOJhvzj7bEZg4wEYa759z1pH4= golang.org/x/mod v0.22.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY= +golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ= +golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA= diff --git a/lint/linter.go b/lint/linter.go index c7230a44f..e8d0a963b 100644 --- a/lint/linter.go +++ b/lint/linter.go @@ -106,7 +106,7 @@ func (l *Linter) Lint(packages [][]string, ruleSet []Rule, config Config) (<-cha wg.Add(1) go func(pkg []string, gover *goversion.Version) { if err := l.lintPackage(pkg, gover, ruleSet, config, failures); err != nil { - fmt.Fprintln(os.Stderr, err) + fmt.Fprintln(os.Stderr, "Error during linting:"+err.Error()) os.Exit(1) } wg.Done() @@ -153,7 +153,6 @@ func (l *Linter) lintPackage(filenames []string, gover *goversion.Version, ruleS } return pkg.lint(ruleSet, config, failures) - } func detectGoMod(dir string) (rootDir string, ver *goversion.Version, err error) { diff --git a/lint/package.go b/lint/package.go index dfefdaba4..56bc5726f 100644 --- a/lint/package.go +++ b/lint/package.go @@ -1,16 +1,15 @@ package lint import ( - "fmt" "errors" "go/ast" "go/importer" "go/token" "go/types" - "os" "sync" goversion "github.com/hashicorp/go-version" + "golang.org/x/sync/errgroup" "github.com/mgechev/revive/internal/astutils" "github.com/mgechev/revive/internal/typeparams" @@ -185,19 +184,20 @@ func (p *Package) scanSortable() { func (p *Package) lint(rules []Rule, config Config, failures chan Failure) error { p.scanSortable() - var wg sync.WaitGroup + var eg errgroup.Group for _, file := range p.files { - wg.Add(1) - go (func(file *File) { + eg.Go(func() error { err := file.lint(rules, config, failures) if err != nil { - fmt.Fprintln(os.Stderr, "Error during linting:", err) - os.Exit(1) + return err } - wg.Done() - })(file) + return nil + }) } - wg.Wait() + if err := eg.Wait(); err != nil { + return err + } + return nil }