1
0
mirror of https://github.com/securego/gosec.git synced 2025-11-27 22:28:20 +02:00

chore(lint): enable errorlint and gci (#698)

This commit is contained in:
Matthieu MOREL
2021-09-13 09:40:10 +02:00
committed by GitHub
parent cb89567f99
commit bfb0f422fe
10 changed files with 216 additions and 23 deletions

View File

@@ -7,7 +7,9 @@ linters:
- dogsled - dogsled
- durationcheck - durationcheck
- errcheck - errcheck
- errorlint
- exportloopref - exportloopref
- gci
- gofmt - gofmt
- gofumpt - gofumpt
- goimports - goimports

View File

@@ -149,7 +149,7 @@ func (gosec *Analyzer) Process(buildTags []string, packagePaths ...string) error
if pkg.Name != "" { if pkg.Name != "" {
err := gosec.ParseErrors(pkg) err := gosec.ParseErrors(pkg)
if err != nil { 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) gosec.Check(pkg)
} }
@@ -173,7 +173,7 @@ func (gosec *Analyzer) load(pkgPath string, conf *packages.Config) ([]*packages.
buildD.BuildTags = conf.BuildFlags buildD.BuildTags = conf.BuildFlags
basePackage, err := buildD.ImportDir(pkgPath, build.ImportComment) basePackage, err := buildD.ImportDir(pkgPath, build.ImportComment)
if err != nil { 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 var packageFiles []string
@@ -197,7 +197,7 @@ func (gosec *Analyzer) load(pkgPath string, conf *packages.Config) ([]*packages.
conf.BuildFlags = nil conf.BuildFlags = nil
pkgs, err := packages.Load(conf, packageFiles...) pkgs, err := packages.Load(conf, packageFiles...)
if err != nil { 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 return pkgs, nil
} }
@@ -257,13 +257,13 @@ func (gosec *Analyzer) ParseErrors(pkg *packages.Package) error {
var line int var line int
if len(parts) > 1 { if len(parts) > 1 {
if line, err = strconv.Atoi(parts[1]); err != nil { 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 var column int
if len(parts) > 2 { if len(parts) > 2 {
if column, err = strconv.Atoi(parts[2]); err != nil { 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) msg := strings.TrimSpace(pkgErr.Msg)

View File

@@ -7,13 +7,12 @@ import (
"os" "os"
"strings" "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/ginkgo"
. "github.com/onsi/gomega" . "github.com/onsi/gomega"
"github.com/securego/gosec/v2"
"github.com/securego/gosec/v2/rules"
"github.com/securego/gosec/v2/testutils" "github.com/securego/gosec/v2/testutils"
"golang.org/x/tools/go/packages"
) )
var _ = Describe("Analyzer", func() { var _ = Describe("Analyzer", func() {

View File

@@ -23,9 +23,8 @@ import (
"sort" "sort"
"strings" "strings"
"github.com/securego/gosec/v2/cmd/vflag"
"github.com/securego/gosec/v2" "github.com/securego/gosec/v2"
"github.com/securego/gosec/v2/cmd/vflag"
"github.com/securego/gosec/v2/report" "github.com/securego/gosec/v2/report"
"github.com/securego/gosec/v2/rules" "github.com/securego/gosec/v2/rules"
) )
@@ -211,7 +210,7 @@ func getRootPaths(paths []string) []string {
for _, path := range paths { for _, path := range paths {
rootPath, err := gosec.RootPath(path) rootPath, err := gosec.RootPath(path)
if err != nil { 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) rootPaths = append(rootPaths, rootPath)
} }

View File

@@ -1,3 +1,4 @@
//go:build go1.14 || !go1.11
// +build go1.14 !go1.11 // +build go1.14 !go1.11
// main // main

View File

@@ -1,3 +1,4 @@
//go:build go1.12
// +build go1.12 // +build go1.12
package main package main

View File

@@ -1,11 +1,10 @@
package gosec_test package gosec_test
import ( import (
"github.com/securego/gosec/v2"
"github.com/securego/gosec/v2/testutils"
. "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo"
. "github.com/onsi/gomega" . "github.com/onsi/gomega"
"github.com/securego/gosec/v2"
"github.com/securego/gosec/v2/testutils"
) )
var _ = Describe("Import Tracker", func() { var _ = Describe("Import Tracker", func() {

View File

@@ -7,7 +7,6 @@ import (
"strings" "strings"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/securego/gosec/v2" "github.com/securego/gosec/v2"
"github.com/securego/gosec/v2/cwe" "github.com/securego/gosec/v2/cwe"
) )

View File

@@ -6,7 +6,6 @@ import (
. "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo"
. "github.com/onsi/gomega" . "github.com/onsi/gomega"
"github.com/securego/gosec/v2" "github.com/securego/gosec/v2"
"github.com/securego/gosec/v2/rules" "github.com/securego/gosec/v2/rules"
"github.com/securego/gosec/v2/testutils" "github.com/securego/gosec/v2/testutils"

File diff suppressed because it is too large Load Diff