Skip to content

Commit

Permalink
Add Golangci-lint static code analysis and fix found issues (#326)
Browse files Browse the repository at this point in the history
  • Loading branch information
sverdlov93 authored May 4, 2023
1 parent 24b1bdb commit 6939acb
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 14 deletions.
16 changes: 9 additions & 7 deletions .github/workflows/analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ jobs:
run: go generate ./...

- name: Static Code Analysis
uses: dominikh/staticcheck-action@v1
uses: golangci/golangci-lint-action@v3
with:
install-go: false
args: |
--timeout 5m --out-${NO_FUTURE}format colored-line-number --enable errcheck,gosimple,govet,ineffassign,staticcheck,typecheck,unused,gocritic,asasalint,asciicheck,errchkjson,exportloopref,forcetypeassert,makezero,nilerr,unparam,unconvert,wastedassign,usestdlibvars
Go-Sec:
runs-on: ubuntu-latest
steps:
Expand All @@ -28,8 +30,8 @@ jobs:
uses: actions/setup-go@v3
with:
go-version: 1.19.x
- name: Install gosec
run: curl -sfL https://raw.githubusercontent.com/securego/gosec/master/install.sh | sh -s -- -b $(go env GOPATH)/bin
- name: Run gosec
# Temporary ignoring G301,G302,G306
run: gosec -exclude=G204,G301,G302,G304,G306 -exclude-dir=\.*test\.* ./...

- name: Run Gosec Security Scanner
uses: securego/gosec@master
with:
args: -exclude=G204,G301,G302,G304,G306 -exclude-dir=\.*test\.* ./...
2 changes: 1 addition & 1 deletion commands/createfixpullrequests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func TestFixPackageVersion(t *testing.T) {
func getTestDataDir(t *testing.T) (string, string) {
currentDir, err := os.Getwd()
assert.NoError(t, err)
testdataDir, err := filepath.Abs(filepath.Join("testdata/projects"))
testdataDir, err := filepath.Abs("testdata/projects")
assert.NoError(t, err)
return currentDir, testdataDir
}
Expand Down
2 changes: 1 addition & 1 deletion commands/scanandfixrepos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ func createHttpHandler(t *testing.T, port *string, projectNames ...string) http.
return
}
if r.RequestURI == fmt.Sprintf("/repos/jfrog/%s/pulls", projectName) {
w.WriteHeader(200)
w.WriteHeader(http.StatusOK)
return
}
if r.RequestURI == fmt.Sprintf("/%s", projectName) {
Expand Down
7 changes: 4 additions & 3 deletions commands/scanpullrequest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -577,11 +577,12 @@ func createGitLabHandler(t *testing.T, projectName string) http.HandlerFunc {
assert.NotEmpty(t, buf.String())

var expectedResponse []byte
if strings.Contains(projectName, "multi-dir") {
switch {
case strings.Contains(projectName, "multi-dir"):
expectedResponse, err = os.ReadFile(filepath.Join("..", "expectedResponseMultiDir.json"))
} else if strings.Contains(projectName, "pip") {
case strings.Contains(projectName, "pip"):
expectedResponse, err = os.ReadFile(filepath.Join("..", "expectedResponsePip.json"))
} else {
default:
expectedResponse, err = os.ReadFile(filepath.Join("..", "expectedResponse.json"))
}
assert.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion commands/scanpullrequests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func fakeRepoDownload(_ context.Context, _, _, testProject, targetDir string) er
// This project will be used in the source auditing phase - mimic a PR with a new vulnerable dependency.
// Second "download" will occur inside the first temp dir. Therefor the "test-proj" will be found and will
// be copied to the second (random) temp dir and will be used in the target auditing phase.
err := fileutils.CopyDir(filepath.Join(testProject), targetDir, true, []string{})
err := fileutils.CopyDir(testProject, targetDir, true, []string{})
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion schema/schemas_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package schema

import (
"fmt"
"io"
"net/http"
"os"
Expand Down Expand Up @@ -135,7 +136,7 @@ func convertYamlToJson(yamlValue interface{}) interface{} {
// "on" is considered a true value for the Yaml Unmarshaler. To work around it, we set the true to be "on".
key = "on"
}
jsonMapping[key.(string)] = convertYamlToJson(value)
jsonMapping[fmt.Sprint(key)] = convertYamlToJson(value)
}
return jsonMapping
case []interface{}:
Expand Down

0 comments on commit 6939acb

Please sign in to comment.