Skip to content

Commit

Permalink
fix issues flagged by golangci-lint
Browse files Browse the repository at this point in the history
The issues flagged by golangci-lint:
https://gist.github.com/dmitris/b2b6836f2e90efa2131a74d8c5253ab7

Related to issue prebid#3519.
  • Loading branch information
dmitris committed Apr 25, 2024
1 parent 5e7c824 commit f730df3
Show file tree
Hide file tree
Showing 40 changed files with 132 additions and 136 deletions.
4 changes: 2 additions & 2 deletions account/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
func GetAccount(ctx context.Context, cfg *config.Configuration, fetcher stored_requests.AccountFetcher, accountID string, me metrics.MetricsEngine) (account *config.Account, errs []error) {
if cfg.AccountRequired && accountID == metrics.PublisherUnknown {
return nil, []error{&errortypes.AcctRequired{
Message: fmt.Sprintf("Prebid-server has been configured to discard requests without a valid Account ID. Please reach out to the prebid server host."),
Message: "Prebid-server has been configured to discard requests without a valid Account ID. Please reach out to the prebid server host.",
}}
}

Expand All @@ -32,7 +32,7 @@ func GetAccount(ctx context.Context, cfg *config.Configuration, fetcher stored_r
}
if cfg.AccountRequired && cfg.AccountDefaults.Disabled {
errs = append(errs, &errortypes.AcctRequired{
Message: fmt.Sprintf("Prebid-server could not verify the Account ID. Please reach out to the prebid server host."),
Message: "Prebid-server could not verify the Account ID. Please reach out to the prebid server host.",
})
return nil, errs
}
Expand Down
2 changes: 1 addition & 1 deletion adapters/adkernelAdn/adkernelAdn.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func compatBannerImpression(imp *openrtb2.Imp) error {
//As banner.w/h are required fields for adkernelAdn platform - take the first format entry
if banner.W == nil && banner.H == nil {
if len(banner.Format) == 0 {
return newBadInputError(fmt.Sprintf("Expected at least one banner.format entry or explicit w/h"))
return newBadInputError("Expected at least one banner.format entry or explicit w/h")
}
format := banner.Format[0]
banner.Format = banner.Format[1:]
Expand Down
6 changes: 3 additions & 3 deletions adapters/adnuntius/adnuntius.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func (a *adapter) generateRequests(ortbRequest openrtb2.BidRequest) ([]*adapters
}}
}

if adnuntiusExt.NoCookies == true {
if adnuntiusExt.NoCookies {
noCookies = true
}

Expand Down Expand Up @@ -463,7 +463,7 @@ func generateBidResponse(adnResponse *AdnResponse, request *openrtb2.BidRequest)
adBid, err := generateAdResponse(ad, imp, adunit.Html, request)
if err != nil {
return nil, []error{&errortypes.BadInput{
Message: fmt.Sprintf("Error at ad generation"),
Message: "Error at ad generation",
}}
}

Expand All @@ -476,7 +476,7 @@ func generateBidResponse(adnResponse *AdnResponse, request *openrtb2.BidRequest)
dealBid, err := generateAdResponse(deal, imp, deal.Html, request)
if err != nil {
return nil, []error{&errortypes.BadInput{
Message: fmt.Sprintf("Error at ad generation"),
Message: "Error at ad generation",
}}
}

Expand Down
3 changes: 2 additions & 1 deletion adapters/adtelligent/adtelligent.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ func validateImpression(imp *openrtb2.Imp) (int, error) {
// common extension for all impressions
var impExtBuffer []byte

impExtBuffer, err = json.Marshal(&adtelligentImpExt{
// TODO: confirm the missing error handling is intended
impExtBuffer, _ /* err */ = json.Marshal(&adtelligentImpExt{
Adtelligent: impExt,
})

Expand Down
1 change: 1 addition & 0 deletions adapters/avocet/avocet.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ func (a *AvocetAdapter) MakeBids(internalRequest *openrtb2.BidRequest, externalR
if len(br.SeatBid[i].Bid[j].Ext) > 0 {
err := json.Unmarshal(br.SeatBid[i].Bid[j].Ext, &ext)
if err != nil {
// TODO: find out why we are not using errs
errs = append(errs, err)
continue
}
Expand Down
4 changes: 1 addition & 3 deletions adapters/beintoo/beintoo.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (a *BeintooAdapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *ada
}}
}

if errors := preprocess(request); errors != nil && len(errors) > 0 {
if errors := preprocess(request); len(errors) > 0 {
return nil, append(errors, &errortypes.BadInput{
Message: fmt.Sprintf("Error in preprocess of Imp, err: %s", errors),
})
Expand Down Expand Up @@ -133,8 +133,6 @@ func addImpProps(imp *openrtb2.Imp, secure *int8, BeintooExt *openrtb_ext.ExtImp
imp.BidFloor = bidFloor
}
}

return
}

// Adding header fields to request header
Expand Down
2 changes: 1 addition & 1 deletion adapters/between/between.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (a *BetweenAdapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *ada
}}
}
ext, errors := preprocess(request)
if errors != nil && len(errors) > 0 {
if len(errors) > 0 {
return nil, errors
}
endpoint, err := a.buildEndpointURL(ext)
Expand Down
4 changes: 1 addition & 3 deletions adapters/cadent_aperture_mx/cadentaperturemx.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (a *adapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *adapters.E
}}
}

if errs := preprocess(request); errs != nil && len(errs) > 0 {
if errs := preprocess(request); len(errs) > 0 {
return nil, append(errs, &errortypes.BadInput{
Message: fmt.Sprintf("Error in preprocess of Imp, err: %s", errs),
})
Expand Down Expand Up @@ -192,8 +192,6 @@ func addImpProps(imp *openrtb2.Imp, secure *int8, cadentExt *openrtb_ext.ExtImpC
imp.BidFloorCur = "USD"
}
}

return
}

// Adding header fields to request header
Expand Down
2 changes: 0 additions & 2 deletions adapters/connectad/connectad.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,6 @@ func addImpInfo(imp *openrtb2.Imp, secure *int8, cadExt *openrtb_ext.ExtImpConne
imp.BidFloor = cadExt.Bidfloor
imp.BidFloorCur = "USD"
}

return
}

func addHeaderIfNonEmpty(headers http.Header, headerName string, headerValue string) {
Expand Down
3 changes: 0 additions & 3 deletions adapters/consumable/consumable.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,10 @@ func (a *adapter) MakeBids(request *openrtb2.BidRequest, requestData *adapters.R
switch bidType {
case openrtb_ext.BidTypeAudio:
seatBid.Bid[i].MType = openrtb2.MarkupAudio
break
case openrtb_ext.BidTypeVideo:
seatBid.Bid[i].MType = openrtb2.MarkupVideo
break
case openrtb_ext.BidTypeBanner:
seatBid.Bid[i].MType = openrtb2.MarkupBanner
break
}
bidResponse.Bids = append(bidResponse.Bids, &adapters.TypedBid{
Bid: &seatBid.Bid[i],
Expand Down
7 changes: 3 additions & 4 deletions adapters/dmx/dmx.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (adapter *DmxAdapter) MakeRequests(request *openrtb2.BidRequest, req *adapt
if dmxReq.App.ID != "" {
anyHasId = true
}
if anyHasId == false {
if !anyHasId {
if idfa, valid := getIdfa(request); valid {
dmxReq.App.ID = idfa
anyHasId = true
Expand Down Expand Up @@ -190,7 +190,7 @@ func (adapter *DmxAdapter) MakeRequests(request *openrtb2.BidRequest, req *adapt

dmxReq.Imp = imps

if anyHasId == false {
if !anyHasId {
return nil, []error{errors.New("This request contained no identifier")}
}

Expand Down Expand Up @@ -264,8 +264,7 @@ func (adapter *DmxAdapter) MakeBids(request *openrtb2.BidRequest, externalReques
}

func fetchParams(params dmxExt, inst openrtb2.Imp, ins openrtb2.Imp, imps []openrtb2.Imp, banner *openrtb2.Banner, video *openrtb2.Video, intVal int8) []openrtb2.Imp {
var tempimp openrtb2.Imp
tempimp = inst
var tempimp openrtb2.Imp = inst
if params.Bidder.Bidfloor != 0 {
tempimp.BidFloor = params.Bidder.Bidfloor
}
Expand Down
7 changes: 3 additions & 4 deletions adapters/gamma/gamma.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func (a *GammaAdapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *adapt
errs = append(errs, err)
return nil, errs
}
var invalidImpIndex = make([]int, 0, 0)
var invalidImpIndex = make([]int, 0)

for i := 0; i < len(request.Imp); i++ {
if request.Imp[i].Banner != nil {
Expand Down Expand Up @@ -182,7 +182,7 @@ func (a *GammaAdapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *adapt
} else if len(request.Imp) == len(invalidImpIndex) {
//only true if every Imp was not a Banner or a Video
err := &errortypes.BadInput{
Message: fmt.Sprintf("No valid impression in the bid request"),
Message: "No valid impression in the bid request",
}
errs = append(errs, err)
return nil, errs
Expand All @@ -205,8 +205,7 @@ func (a *GammaAdapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *adapt
}

func convertBid(gBid gammaBid, mediaType openrtb_ext.BidType) *openrtb2.Bid {
var bid openrtb2.Bid
bid = gBid.Bid
var bid openrtb2.Bid = gBid.Bid

if mediaType == openrtb_ext.BidTypeVideo {
//Return inline VAST XML Document (Section 6.4.2)
Expand Down
2 changes: 2 additions & 0 deletions adapters/lemmadigital/lemmadigital.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ func (a *adapter) MakeBids(request *openrtb2.BidRequest, requestData *adapters.R
}
bidResponse.Bids = append(bidResponse.Bids, b)
}
// golangci-lint staticheck SA4004: the surrounding loop is unconditionally terminated
// TODO: confirm the break is intended and add '// nosemgrep: SA4004'
break
}

Expand Down
2 changes: 2 additions & 0 deletions adapters/minutemedia/minutemedia.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ func extractOrg(openRTBRequest *openrtb2.BidRequest) (string, error) {
return "", fmt.Errorf("failed to unmarshal ImpExtMinuteMedia: %w", err)
}

// golangci-lint staticcheck SA4004: the surrounding loop is unconditionally terminated
// TODO: confirm this is intended and add '// nosemgrep: SA4004'
return strings.TrimSpace(impExt.Org), nil
}

Expand Down
2 changes: 1 addition & 1 deletion adapters/rubicon/rubicon.go
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ func createImpsToExtMap(imps []openrtb2.Imp) (map[*openrtb2.Imp]rubiconExtImpBid
func prepareImpsToExtMap(impsToExtMap map[*openrtb2.Imp]rubiconExtImpBidder) map[*openrtb2.Imp]rubiconExtImpBidder {
preparedImpsToExtMap := make(map[*openrtb2.Imp]rubiconExtImpBidder)
for imp, bidderExt := range impsToExtMap {
if bidderExt.Bidder.BidOnMultiformat == false {
if !bidderExt.Bidder.BidOnMultiformat {
impCopy := imp
preparedImpsToExtMap[impCopy] = bidderExt
continue
Expand Down
6 changes: 3 additions & 3 deletions adapters/smartrtb/smartrtb.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ type bidRequestExt struct {
// bidExt.CreativeType values.
const (
creativeTypeBanner string = "BANNER"
creativeTypeVideo = "VIDEO"
creativeTypeNative = "NATIVE"
creativeTypeAudio = "AUDIO"
creativeTypeVideo string = "VIDEO"
creativeTypeNative string = "NATIVE"
creativeTypeAudio string = "AUDIO"
)

// Bid response extension from downstream.
Expand Down
6 changes: 3 additions & 3 deletions adapters/sovrnXsp/sovrnXsp.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ type adapter struct {
// bidExt.CreativeType values.
const (
creativeTypeBanner int = 0
creativeTypeVideo = 1
creativeTypeNative = 2
creativeTypeAudio = 3
creativeTypeVideo int = 1
creativeTypeNative int = 2
creativeTypeAudio int = 3
)

// Bid response extension from XSP.
Expand Down
8 changes: 6 additions & 2 deletions adapters/tappx/tappx.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ func (a *TappxAdapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *adapt
}}
}

var test int
test = int(request.Test)
test := int(request.Test)

url, err := a.buildEndpointURL(&tappxExt, test)
if url == "" {
Expand Down Expand Up @@ -134,6 +133,11 @@ func (a *TappxAdapter) buildEndpointURL(params *openrtb_ext.ExtImpTappx, test in

tappxHost := "tappx.com"
isNewEndpoint, err := regexp.Match(`^(zz|vz)[0-9]{3,}([a-z]{2,3}|test)$`, []byte(params.Endpoint))
if err != nil {
return "", &errortypes.BadInput{
Message: "Unable to match params.Endpoint " + string(params.Endpoint) + "): " + err.Error(),
}
}
if isNewEndpoint {
tappxHost = params.Endpoint + ".pub.tappx.com/rtb/"
} else {
Expand Down
7 changes: 5 additions & 2 deletions adapters/tappx/tappx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,16 @@ func TestTsValue(t *testing.T) {

bidderTappx := bidder.(*TappxAdapter)

var test int
test = 0
var test int = 0
var tappxExt openrtb_ext.ExtImpTappx
tappxExt.Endpoint = "DUMMYENDPOINT"
tappxExt.TappxKey = "dummy-tappx-key"

url, err := bidderTappx.buildEndpointURL(&tappxExt, test)
if err != nil {
t.Errorf("Error in buildEndpointURL: %s", err.Error())
return
}

match, err := regexp.MatchString(`http://ssp\.api\.tappx\.com/rtb/v2/DUMMYENDPOINT\?tappxkey=dummy-tappx-key&ts=[0-9]{13}&type_cnn=prebid&v=1\.5`, url)
if err != nil {
Expand Down
12 changes: 6 additions & 6 deletions adapters/yieldlab/yieldlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -498,20 +498,20 @@ func makeSupplyChain(openRtbSchain openrtb2.SupplyChain) string {

// makeNodeValue converts any known value type from a schain node to a string and does URL encoding if necessary.
func makeNodeValue(nodeParam any) string {
switch nodeParam.(type) {
switch nodeParam := nodeParam.(type) {
case string:
return url.QueryEscape(nodeParam.(string))
return url.QueryEscape(nodeParam)
case *int8:
pointer := nodeParam.(*int8)
pointer := nodeParam
if pointer == nil {
return ""
}
return makeNodeValue(int(*pointer))
case int:
return strconv.Itoa(nodeParam.(int))
return strconv.Itoa(nodeParam)
case json.RawMessage:
if freeFormData := nodeParam.(json.RawMessage); freeFormData != nil {
freeFormJson, err := json.Marshal(freeFormData)
if nodeParam != nil {
freeFormJson, err := json.Marshal(nodeParam)
if err != nil {
return ""
}
Expand Down
2 changes: 0 additions & 2 deletions adapters/yieldmo/yieldmo.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,12 @@ type ExtBid struct {
}

func (a *YieldmoAdapter) MakeRequests(request *openrtb2.BidRequest, reqInfo *adapters.ExtraRequestInfo) ([]*adapters.RequestData, []error) {
var errs []error
var adapterRequests []*adapters.RequestData

adapterReq, errors := a.makeRequest(request)
if adapterReq != nil {
adapterRequests = append(adapterRequests, adapterReq)
}
errs = append(errs, errors...)

return adapterRequests, errors
}
Expand Down
5 changes: 3 additions & 2 deletions adservertargeting/respdataprocessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,14 @@ func buildBidExt(targetingData map[string]string,
}
bidExtTargeting, err := jsonutil.Marshal(bidExtTargetingData)
if err != nil {
warnings = append(warnings, createWarning(err.Error()))
// TODO: figure out the intended usage of warnings, here and several lines below
// warnings = append(warnings, createWarning(err.Error()))
return nil
}

newExt, err := jsonpatch.MergePatch(bid.Ext, bidExtTargeting)
if err != nil {
warnings = append(warnings, createWarning(err.Error()))
// warnings = append(warnings, createWarning(err.Error()))
return nil
}
return newExt
Expand Down
2 changes: 1 addition & 1 deletion bidadjustment/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const minBid = 0.1

// Apply gets the highest priority adjustment slice given a map of rules, and applies those adjustments to a bid's price
func Apply(rules map[string][]openrtb_ext.Adjustment, bidInfo *adapters.TypedBid, bidderName openrtb_ext.BidderName, currency string, reqInfo *adapters.ExtraRequestInfo, bidType string) (float64, string) {
adjustments := []openrtb_ext.Adjustment{}
var adjustments []openrtb_ext.Adjustment
if len(rules) > 0 {
adjustments = get(rules, bidType, string(bidderName), bidInfo.Bid.DealID)
} else {
Expand Down
Loading

0 comments on commit f730df3

Please sign in to comment.