Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address some linting issues #390

Merged
merged 1 commit into from
Apr 13, 2022
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
6 changes: 5 additions & 1 deletion hack/generate/generate.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"fmt"
"io/ioutil"
"log"
"os"
Expand Down Expand Up @@ -95,11 +96,14 @@ func mustWriteTemplates(jobs []templateJob) {
if err != nil {
log.Fatal(err)
}
tmpl.Execute(f, templateData{
err = tmpl.Execute(f, templateData{
NameTitle: nameTitle,
NameLower: nameLower,
NameUpper: nameUpper,
})
if err != nil {
log.Fatal(fmt.Errorf("failed to execute template: %w", err))
}
}
}

Expand Down
5 changes: 4 additions & 1 deletion pkg/common/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ func testFilterWriteFile(filename string, content []byte) error {
if err != nil {
return err
}
f.Write(content)
_, err = f.Write(content)
if err != nil {
return err
}
return f.Close()
}
5 changes: 3 additions & 2 deletions pkg/detectors/bitfinex/bitfinex.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package bitfinex
import (
"context"
"flag"
"net/http"
"regexp"
"strings"

Expand All @@ -27,8 +28,7 @@ var (
)

var (
orderid = flag.String("id", "", "lookup trades for an order ID")
api = flag.String("api", "https://api-pub.bitfinex.com/v2/", "v2 REST API URL")
api = flag.String("api", "https://api-pub.bitfinex.com/v2/", "v2 REST API URL")
)

// Keywords are used for efficiently pre-filtering chunks.
Expand Down Expand Up @@ -69,6 +69,7 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
// thankfully official golang examples exist but you just need to dig their many repos https://github.com/bitfinexcom/bitfinex-api-go/blob/master/examples/v2/rest-orders/main.go
key := apiKeyRes
secret := apiSecretRes
http.DefaultClient = client // filed https://github.com/bitfinexcom/bitfinex-api-go/issues/238 to improve this
c := rest.NewClientWithURL(*api).Credentials(key, secret)

isValid := true // assume valid
Expand Down
8 changes: 0 additions & 8 deletions pkg/detectors/bitfinex/bitfinex_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ func TestBitfinex_FromChunk(t *testing.T) {
DetectorType: detectorspb.DetectorType_Bitfinex,
Verified: true,
},
{
DetectorType: detectorspb.DetectorType_Bitfinex,
Verified: false,
},
},
wantErr: false,
},
Expand All @@ -70,10 +66,6 @@ func TestBitfinex_FromChunk(t *testing.T) {
DetectorType: detectorspb.DetectorType_Bitfinex,
Verified: false,
},
{
DetectorType: detectorspb.DetectorType_Bitfinex,
Verified: false,
},
},
wantErr: false,
},
Expand Down
75 changes: 0 additions & 75 deletions pkg/detectors/buddyns/buddyns/buddyns.go

This file was deleted.

113 changes: 0 additions & 113 deletions pkg/detectors/buddyns/buddyns/buddyns_test.go

This file was deleted.

4 changes: 0 additions & 4 deletions pkg/detectors/elasticemail/elasticemail.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,3 @@ func (s Scanner) FromData(ctx context.Context, verify bool, data []byte) (result
}
return detectors.CleanResults(results), nil
}
func prettyPrint(i interface{}) string {
s, _ := json.MarshalIndent(i, "", "\t")
return string(s)
}
38 changes: 19 additions & 19 deletions pkg/detectors/generic/generic.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,22 +118,22 @@ func hasReMatch(matchers []*regexp.Regexp, token string) bool {
return false
}

func hasDictWord(wordList []string, token string) bool {
lower := strings.ToLower(token)
for _, word := range wordList {
if strings.Contains(lower, word) {
return true
}
}
return false
}

func bytesToCleanWordList(data []byte) []string {
words := []string{}
for _, word := range strings.Split(string(data), "\n") {
if strings.TrimSpace(word) != "" {
words = append(words, strings.TrimSpace(strings.ToLower(word)))
}
}
return words
}
// func hasDictWord(wordList []string, token string) bool {
// lower := strings.ToLower(token)
// for _, word := range wordList {
// if strings.Contains(lower, word) {
// return true
// }
// }
// return false
// }

// func bytesToCleanWordList(data []byte) []string {
// words := []string{}
// for _, word := range strings.Split(string(data), "\n") {
// if strings.TrimSpace(word) != "" {
// words = append(words, strings.TrimSpace(strings.ToLower(word)))
// }
// }
// return words
// }
2 changes: 0 additions & 2 deletions pkg/detectors/privatekey/normalize.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"strings"
)

const b64chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="

func normalize(in string) string {
in = strings.ReplaceAll(in, `"`, "")
in = strings.ReplaceAll(in, `'`, "")
Expand Down
1 change: 1 addition & 0 deletions pkg/detectors/privatekey/privatekey.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type Scanner struct {
var _ detectors.Detector = (*Scanner)(nil)

var (
// TODO: add base64 encoded key support
client = common.RetryableHttpClient()
keyPat = regexp.MustCompile(`(?i)-----\s*?BEGIN[ A-Z0-9_-]*?PRIVATE KEY\s*?-----[\s\S]*?----\s*?END[ A-Z0-9_-]*? PRIVATE KEY\s*?-----`)
)
Expand Down
4 changes: 2 additions & 2 deletions pkg/output/legacy_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func BranchHeads(repo *gogit.Repository) (map[string]*object.Commit, error) {
return branches, err
}

branchIter.ForEach(func(branchRef *plumbing.Reference) error {
err = branchIter.ForEach(func(branchRef *plumbing.Reference) error {
branchName := branchRef.Name().String()
headHash, err := repo.ResolveRevision(plumbing.Revision(branchName))
if err != nil {
Expand All @@ -88,7 +88,7 @@ func BranchHeads(repo *gogit.Repository) (map[string]*object.Commit, error) {
branches[branchName] = headCommit
return nil
})
return branches, nil
return branches, err
}

// FindBranch returns the first branch a commit is a part of. Not the most accurate, but it should work similar to pre v3.0.
Expand Down