Skip to content

Commit

Permalink
package: handle errgroup.Group
Browse files Browse the repository at this point in the history
  • Loading branch information
mfederowicz committed Dec 7, 2024
1 parent 0022083 commit 9c9e05e
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
3 changes: 1 addition & 2 deletions lint/linter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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) {
Expand Down
20 changes: 10 additions & 10 deletions lint/package.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 9c9e05e

Please sign in to comment.