mirror of
https://github.com/securego/gosec.git
synced 2024-11-05 11:35:51 +00:00
chore(lint): enable errorlint and gci (#698)
This commit is contained in:
parent
cb89567f99
commit
bfb0f422fe
10 changed files with 216 additions and 23 deletions
|
@ -7,7 +7,9 @@ linters:
|
|||
- dogsled
|
||||
- durationcheck
|
||||
- errcheck
|
||||
- errorlint
|
||||
- exportloopref
|
||||
- gci
|
||||
- gofmt
|
||||
- gofumpt
|
||||
- goimports
|
||||
|
|
10
analyzer.go
10
analyzer.go
|
@ -149,7 +149,7 @@ func (gosec *Analyzer) Process(buildTags []string, packagePaths ...string) error
|
|||
if pkg.Name != "" {
|
||||
err := gosec.ParseErrors(pkg)
|
||||
if err != nil {
|
||||
return fmt.Errorf("parsing errors in pkg %q: %v", pkg.Name, err)
|
||||
return fmt.Errorf("parsing errors in pkg %q: %w", pkg.Name, err)
|
||||
}
|
||||
gosec.Check(pkg)
|
||||
}
|
||||
|
@ -173,7 +173,7 @@ func (gosec *Analyzer) load(pkgPath string, conf *packages.Config) ([]*packages.
|
|||
buildD.BuildTags = conf.BuildFlags
|
||||
basePackage, err := buildD.ImportDir(pkgPath, build.ImportComment)
|
||||
if err != nil {
|
||||
return []*packages.Package{}, fmt.Errorf("importing dir %q: %v", pkgPath, err)
|
||||
return []*packages.Package{}, fmt.Errorf("importing dir %q: %w", pkgPath, err)
|
||||
}
|
||||
|
||||
var packageFiles []string
|
||||
|
@ -197,7 +197,7 @@ func (gosec *Analyzer) load(pkgPath string, conf *packages.Config) ([]*packages.
|
|||
conf.BuildFlags = nil
|
||||
pkgs, err := packages.Load(conf, packageFiles...)
|
||||
if err != nil {
|
||||
return []*packages.Package{}, fmt.Errorf("loading files from package %q: %v", pkgPath, err)
|
||||
return []*packages.Package{}, fmt.Errorf("loading files from package %q: %w", pkgPath, err)
|
||||
}
|
||||
return pkgs, nil
|
||||
}
|
||||
|
@ -257,13 +257,13 @@ func (gosec *Analyzer) ParseErrors(pkg *packages.Package) error {
|
|||
var line int
|
||||
if len(parts) > 1 {
|
||||
if line, err = strconv.Atoi(parts[1]); err != nil {
|
||||
return fmt.Errorf("parsing line: %v", err)
|
||||
return fmt.Errorf("parsing line: %w", err)
|
||||
}
|
||||
}
|
||||
var column int
|
||||
if len(parts) > 2 {
|
||||
if column, err = strconv.Atoi(parts[2]); err != nil {
|
||||
return fmt.Errorf("parsing column: %v", err)
|
||||
return fmt.Errorf("parsing column: %w", err)
|
||||
}
|
||||
}
|
||||
msg := strings.TrimSpace(pkgErr.Msg)
|
||||
|
|
|
@ -7,13 +7,12 @@ import (
|
|||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/securego/gosec/v2"
|
||||
"github.com/securego/gosec/v2/rules"
|
||||
"golang.org/x/tools/go/packages"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
"github.com/securego/gosec/v2"
|
||||
"github.com/securego/gosec/v2/rules"
|
||||
"github.com/securego/gosec/v2/testutils"
|
||||
"golang.org/x/tools/go/packages"
|
||||
)
|
||||
|
||||
var _ = Describe("Analyzer", func() {
|
||||
|
|
|
@ -23,9 +23,8 @@ import (
|
|||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/securego/gosec/v2/cmd/vflag"
|
||||
|
||||
"github.com/securego/gosec/v2"
|
||||
"github.com/securego/gosec/v2/cmd/vflag"
|
||||
"github.com/securego/gosec/v2/report"
|
||||
"github.com/securego/gosec/v2/rules"
|
||||
)
|
||||
|
@ -211,7 +210,7 @@ func getRootPaths(paths []string) []string {
|
|||
for _, path := range paths {
|
||||
rootPath, err := gosec.RootPath(path)
|
||||
if err != nil {
|
||||
logger.Fatal(fmt.Errorf("failed to get the root path of the projects: %s", err))
|
||||
logger.Fatal(fmt.Errorf("failed to get the root path of the projects: %w", err))
|
||||
}
|
||||
rootPaths = append(rootPaths, rootPath)
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
//go:build go1.14 || !go1.11
|
||||
// +build go1.14 !go1.11
|
||||
|
||||
// main
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
//go:build go1.12
|
||||
// +build go1.12
|
||||
|
||||
package main
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
package gosec_test
|
||||
|
||||
import (
|
||||
"github.com/securego/gosec/v2"
|
||||
"github.com/securego/gosec/v2/testutils"
|
||||
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
"github.com/securego/gosec/v2"
|
||||
"github.com/securego/gosec/v2/testutils"
|
||||
)
|
||||
|
||||
var _ = Describe("Import Tracker", func() {
|
||||
|
|
|
@ -7,7 +7,6 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/google/uuid"
|
||||
|
||||
"github.com/securego/gosec/v2"
|
||||
"github.com/securego/gosec/v2/cwe"
|
||||
)
|
||||
|
|
|
@ -6,7 +6,6 @@ import (
|
|||
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
|
||||
"github.com/securego/gosec/v2"
|
||||
"github.com/securego/gosec/v2/rules"
|
||||
"github.com/securego/gosec/v2/testutils"
|
||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue