Skip to content
This repository has been archived by the owner on Nov 23, 2021. It is now read-only.

golint: minor fixes #36

Merged
merged 1 commit into from
Sep 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions deplist.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ func init() {
}
}

// GetLanguageStr returns from a bitmask return the ecosystem name
func GetLanguageStr(bm Bitmask) string {
if bm&LangGolang != 0 {
return "go"
Expand Down
15 changes: 10 additions & 5 deletions internal/scan/golang.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
"golang.org/x/mod/semver"
)

// GoListDeps holds the import path, version and gofiles for a given go
// dependency
type GoListDeps struct {
ImportPath string `json:"ImportPath"`
Module struct {
Expand All @@ -25,14 +27,15 @@ type GoListDeps struct {
GoFiles []string `json:"GoFiles"`
}

// GoPkg holds the version and go paths/files for a given dep
type GoPkg struct {
Version string
Gofiles []string
}

func getVersion(deps GoListDeps) string {
/* if replace is specified, then use that version
* not seen when version and replace.version are differnt
* not seen when version and replace.version are different
* but just in case
*/
if deps.Module.Replace.Version != "" {
Expand Down Expand Up @@ -75,10 +78,10 @@ func runCmd(path string, mod bool) ([]byte, error) {
if !mod {
// assume some retrival error, we have to redo the cmd with mod=vendor
return nil, err
} else {
if len(out) == 0 {
return nil, err
}
}

if len(out) == 0 {
return nil, err
}
}

Expand All @@ -102,6 +105,8 @@ func runGoList(path string) ([]byte, error) {
return out, nil
}

// GetGolangDeps uses `go list` gather a list of dependencies located at `path`
// returning an array of `GoPkg` structs
func GetGolangDeps(path string) (map[string]GoPkg, error) {
// need to use a map as we'll get lots of duplicate entries
gathered := make(map[string]GoPkg)
Expand Down
1 change: 1 addition & 0 deletions internal/scan/jar.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/mcoops/jargo"
)

// GetJarDeps uses github.com/mcoops/jargo retrieve the java dependencies
func GetJarDeps(path string) (map[string]string, error) {
gathered := make(map[string]string)

Expand Down
4 changes: 3 additions & 1 deletion internal/scan/maven.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"strings"
)

// GetMvnDeps uses the mvn command to attempt to list the dependencies for a
// given project located at `path`
func GetMvnDeps(path string) (map[string]string, error) {
var gathered map[string]string
var found map[string]bool
Expand All @@ -27,7 +29,7 @@ func GetMvnDeps(path string) (map[string]string, error) {
"-DincludeScope=runtime")
cmd.Dir = dirPath

// supress error, it always returns errors
// suppress error, it always returns errors
data, _ := cmd.Output()

res := strings.Split(string(data), "\n")
Expand Down
4 changes: 4 additions & 0 deletions internal/scan/nodejs.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type npmListOutput struct {
Dependencies map[string]npmDependency `json:"dependencies"`
}

// NodeJSGather dependencies found, name and version
type NodeJSGather struct {
Name string
Version string
Expand Down Expand Up @@ -86,6 +87,9 @@ func gatherNPMNode(name string, dependency npmDependency) {
}
}

// GetNodeJSDeps scans the path for either `yarn.lock` or `package-lock.json`,
// then use the appropriate pkg managers to produce depencies lists of type
// `NodeJSGather`
func GetNodeJSDeps(path string) (map[string]NodeJSGather, error) {
switch filepath.Base(path) {
case "yarn.lock":
Expand Down
3 changes: 2 additions & 1 deletion internal/scan/python.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
// Account for >, <, >=, <=, ==, !=, ~= and *
var /* const */ re = regexp.MustCompile(`[<>!~*]+`)

// GetPythonDeps scans path for python deps using the `requirements.txt` file
func GetPythonDeps(path string) (map[string]string, error) {
gathered := make(map[string]string)

Expand Down Expand Up @@ -40,7 +41,7 @@ func GetPythonDeps(path string) (map[string]string, error) {
}

// every other permitation just use the name as we can't guarantee
// the version, just grab the name using first occurance
// the version, just grab the name using first occurrence
match := re.FindStringIndex(line)

if match != nil {
Expand Down
12 changes: 7 additions & 5 deletions internal/scan/ruby.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,27 @@ import (
"strings"
)

// GetRubyDeps uses `bundle update --bundler` to list ruby dependencies when a
// Gemfile.lock file exists
func GetRubyDeps(path string) (map[string]string, error) {
gathered := make(map[string]string)

dirPath := filepath.Dir(path)

// override the gem path otherwise might hit perm issues and it's annoying
gem_path, err := os.MkdirTemp("", "gem_vendor")
gemPath, err := os.MkdirTemp("", "gem_vendor")
if err != nil {
return nil, err
}

// cleanup after ourselves
defer os.RemoveAll(gem_path)
defer os.RemoveAll(gemPath)

//Make sure that the Gemfile we are loading is supported by the version of bundle currently installed.
cmd := exec.Command("bundle", "update", "--bundler")
cmd.Dir = dirPath
cmd.Env = os.Environ()
cmd.Env = append(cmd.Env, "BUNDLE_PATH="+gem_path)
cmd.Env = append(cmd.Env, "BUNDLE_PATH="+gemPath)
_, err = cmd.Output()
if err != nil {
return nil, err
Expand All @@ -36,11 +38,11 @@ func GetRubyDeps(path string) (map[string]string, error) {

cmd.Dir = dirPath
cmd.Env = os.Environ()
cmd.Env = append(cmd.Env, "BUNDLE_PATH="+gem_path)
cmd.Env = append(cmd.Env, "BUNDLE_PATH="+gemPath)

data, err := cmd.Output()
if err != nil {
return nil, errors.New(gem_path + " " + err.Error())
return nil, errors.New(gemPath + " " + err.Error())
}

splitOutput := strings.Split(string(data), "\n")
Expand Down
2 changes: 1 addition & 1 deletion internal/utils/utils.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package utils

// fastest way we can do a string compare on a list
// BelongsToIgnoreList is fastest way we can do a string compare on a list
func BelongsToIgnoreList(needle string) bool {
switch needle {
case
Expand Down