Skip to content

Commit

Permalink
Address some linting issues (#390)
Browse files Browse the repository at this point in the history
  • Loading branch information
dustin-decker authored Apr 13, 2022
1 parent ad82a8e commit dd86389
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 227 deletions.
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

0 comments on commit dd86389

Please sign in to comment.