Skip to content

Commit

Permalink
chore(lint): enable errorlint and gci (#698)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmorel-35 authored Sep 13, 2021
1 parent cb89567 commit bfb0f42
Show file tree
Hide file tree
Showing 10 changed files with 216 additions and 23 deletions.
2 changes: 2 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ linters:
- dogsled
- durationcheck
- errcheck
- errorlint
- exportloopref
- gci
- gofmt
- gofumpt
- goimports
Expand Down
10 changes: 5 additions & 5 deletions analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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
Expand All @@ -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
}
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 3 additions & 4 deletions analyzer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
5 changes: 2 additions & 3 deletions cmd/gosec/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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)
}
Expand Down
1 change: 1 addition & 0 deletions cmd/tlsconfig/tls_version_go14.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build go1.14 || !go1.11
// +build go1.14 !go1.11

// main
Expand Down
1 change: 1 addition & 0 deletions cmd/tlsconfig/tlsconfig.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build go1.12
// +build go1.12

package main
Expand Down
5 changes: 2 additions & 3 deletions import_tracker_test.go
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down
1 change: 0 additions & 1 deletion report/sarif/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"strings"

"github.com/google/uuid"

"github.com/securego/gosec/v2"
"github.com/securego/gosec/v2/cwe"
)
Expand Down
1 change: 0 additions & 1 deletion rules/rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading

0 comments on commit bfb0f42

Please sign in to comment.