From 3af4ae9ddb5eee0f6cf73c061657fe570b03bf80 Mon Sep 17 00:00:00 2001 From: Cosmin Cojocar Date: Tue, 30 Apr 2019 11:32:06 +0200 Subject: [PATCH] Fix some lint warnings Signed-off-by: Cosmin Cojocar --- analyzer.go | 6 +++--- issue.go | 7 +++++-- rules/fileperms.go | 6 +++--- testutils/pkg.go | 6 ------ 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/analyzer.go b/analyzer.go index 3dc2c48..b0bcbf9 100644 --- a/analyzer.go +++ b/analyzer.go @@ -231,11 +231,11 @@ func (gosec *Analyzer) ignore(n ast.Node) ([]string, bool) { gosec.stats.NumNosec++ // Pull out the specific rules that are listed to be ignored. - re := regexp.MustCompile("(G\\d{3})") + re := regexp.MustCompile(`(G\d{3})`) matches := re.FindAllStringSubmatch(group.Text(), -1) // If no specific rules were given, ignore everything. - if matches == nil || len(matches) == 0 { + if len(matches) == 0 { return nil, true } @@ -269,7 +269,7 @@ func (gosec *Analyzer) Visit(n ast.Node) ast.Visitor { } // Now create the union of exclusions. - ignores := make(map[string]bool, 0) + ignores := map[string]bool{} if len(gosec.context.Ignores) > 0 { for k, v := range gosec.context.Ignores[0] { ignores[k] = v diff --git a/issue.go b/issue.go index 6a2aa54..9f0454e 100644 --- a/issue.go +++ b/issue.go @@ -77,8 +77,11 @@ func codeSnippet(file *os.File, start int64, end int64, n ast.Node) (string, err return "", fmt.Errorf("Invalid AST node provided") } - size := (int)(end - start) // Go bug, os.File.Read should return int64 ... - file.Seek(start, 0) // #nosec + size := (int)(end - start) // Go bug, os.File.Read should return int64 ... + _, err := file.Seek(start, 0) // #nosec + if err != nil { + return "", fmt.Errorf("move to the beginning of file: %v", err) + } buf := make([]byte, size) if nread, err := file.Read(buf); err != nil || nread != size { diff --git a/rules/fileperms.go b/rules/fileperms.go index 8e94369..2a56f35 100644 --- a/rules/fileperms.go +++ b/rules/fileperms.go @@ -36,11 +36,11 @@ func (r *filePermissions) ID() string { func getConfiguredMode(conf map[string]interface{}, configKey string, defaultMode int64) int64 { var mode = defaultMode if value, ok := conf[configKey]; ok { - switch value.(type) { + switch value := value.(type) { case int64: - mode = value.(int64) + mode = value case string: - if m, e := strconv.ParseInt(value.(string), 0, 64); e != nil { + if m, e := strconv.ParseInt(value, 0, 64); e != nil { mode = defaultMode } else { mode = m diff --git a/testutils/pkg.go b/testutils/pkg.go index 0842b05..fcc7c4f 100644 --- a/testutils/pkg.go +++ b/testutils/pkg.go @@ -30,12 +30,6 @@ type TestPackage struct { // NewTestPackage will create a new and empty package. Must call Close() to cleanup // auxiliary files func NewTestPackage() *TestPackage { - goPath := os.Getenv("GOPATH") - // if user did not set GOPATH, set to the default - if goPath == "" { - goPath = build.Default.GOPATH - } - workingDir, err := ioutil.TempDir("", "gosecs_test") if err != nil { return nil