Skip to content

Commit

Permalink
lint: fix all violations on master
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobbednarz committed Aug 1, 2021
1 parent c7636ba commit 0a96140
Show file tree
Hide file tree
Showing 18 changed files with 113 additions and 221 deletions.
12 changes: 6 additions & 6 deletions cloudflare_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestClient_Headers(t *testing.T) {
assert.Equal(t, "deadbeef", r.Header.Get("X-Auth-Key"))
assert.Equal(t, "application/json", r.Header.Get("Content-Type"))
})
client.UserDetails(context.Background())
client.UserDetails(context.Background()) //nolint
teardown()

// it should override appropriate default headers when custom headers given
Expand All @@ -63,7 +63,7 @@ func TestClient_Headers(t *testing.T) {
assert.Equal(t, "application/xhtml+xml", r.Header.Get("Content-Type"))
assert.Equal(t, "a random header", r.Header.Get("X-Random"))
})
client.UserDetails(context.Background())
client.UserDetails(context.Background()) //nolint
teardown()

// it should set X-Auth-User-Service-Key and omit X-Auth-Email and X-Auth-Key when client.authType is AuthUserService
Expand All @@ -78,7 +78,7 @@ func TestClient_Headers(t *testing.T) {
assert.Equal(t, "userservicekey", r.Header.Get("X-Auth-User-Service-Key"))
assert.Equal(t, "application/json", r.Header.Get("Content-Type"))
})
client.UserDetails(context.Background())
client.UserDetails(context.Background()) //nolint
teardown()

// it should set X-Auth-User-Service-Key and omit X-Auth-Email and X-Auth-Key when using NewWithUserServiceKey
Expand All @@ -94,7 +94,7 @@ func TestClient_Headers(t *testing.T) {
assert.Equal(t, "userservicekey", r.Header.Get("X-Auth-User-Service-Key"))
assert.Equal(t, "application/json", r.Header.Get("Content-Type"))
})
client.UserDetails(context.Background())
client.UserDetails(context.Background()) //nolint
teardown()

// it should set Authorization and omit others credential headers when using NewWithAPIToken
Expand All @@ -110,7 +110,7 @@ func TestClient_Headers(t *testing.T) {
assert.Equal(t, "Bearer my-api-token", r.Header.Get("Authorization"))
assert.Equal(t, "application/json", r.Header.Get("Content-Type"))
})
client.UserDetails(context.Background())
client.UserDetails(context.Background()) //nolint
teardown()
}

Expand Down Expand Up @@ -458,7 +458,7 @@ func TestClient_ContextIsPassedToRequest(t *testing.T) {

cfClient, _ := New("deadbeef", "[email protected]", HTTPClient(httpClient))

cfClient.ListZonesContext(ctx)
cfClient.ListZonesContext(ctx) //nolint
}

func TestErrorFromResponseWithUnmarshalingError(t *testing.T) {
Expand Down
12 changes: 6 additions & 6 deletions cmd/flarectl/firewall.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,19 +169,19 @@ func firewallAccessRuleUpdate(c *cli.Context) error {
case accountID != "":
resp, err := api.UpdateAccountAccessRule(context.Background(), accountID, id, rule)
if err != nil {
errors.Wrap(err, errUpdating)
errors.Wrap(err, errUpdating) //nolint
}
rules = append(rules, resp.Result)
case zoneID != "":
resp, err := api.UpdateZoneAccessRule(context.Background(), zoneID, id, rule)
if err != nil {
errors.Wrap(err, errUpdating)
errors.Wrap(err, errUpdating) //nolint
}
rules = append(rules, resp.Result)
default:
resp, err := api.UpdateUserAccessRule(context.Background(), id, rule)
if err != nil {
errors.Wrap(err, errUpdating)
errors.Wrap(err, errUpdating) //nolint
}
rules = append(rules, resp.Result)
}
Expand Down Expand Up @@ -285,19 +285,19 @@ func firewallAccessRuleDelete(c *cli.Context) error {
case accountID != "":
resp, err := api.DeleteAccountAccessRule(context.Background(), accountID, ruleID)
if err != nil {
errors.Wrap(err, errDeleting)
errors.Wrap(err, errDeleting) //nolint
}
rules = append(rules, resp.Result)
case zoneID != "":
resp, err := api.DeleteZoneAccessRule(context.Background(), zoneID, ruleID)
if err != nil {
errors.Wrap(err, errDeleting)
errors.Wrap(err, errDeleting) //nolint
}
rules = append(rules, resp.Result)
default:
resp, err := api.DeleteUserAccessRule(context.Background(), ruleID)
if err != nil {
errors.Wrap(err, errDeleting)
errors.Wrap(err, errDeleting) //nolint
}
rules = append(rules, resp.Result)
}
Expand Down
8 changes: 4 additions & 4 deletions cmd/flarectl/flarectl.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (
)

var (
version = "dev"
commit = "none"
date = "unknown"
builtBy = "unknown"
version = "dev" //nolint
commit = "none" //nolint
date = "unknown" //nolint
builtBy = "unknown" //nolint
)

var api *cloudflare.API
Expand Down
10 changes: 5 additions & 5 deletions cmd/flarectl/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func initializeAPI(c *cli.Context) error {
}

if c.IsSet("accountid") {
cloudflare.UsingAccount(c.String("accountid"))(api)
cloudflare.UsingAccount(c.String("accountid"))(api) //nolint
}

return nil
Expand Down Expand Up @@ -92,7 +92,7 @@ func writeTable(c *cli.Context, data [][]string, cols ...string) {
func checkFlags(c *cli.Context, flags ...string) error {
for _, flag := range flags {
if c.String(flag) == "" {
cli.ShowSubcommandHelp(c)
cli.ShowSubcommandHelp(c) //nolint
err := errors.Errorf("error: the required flag %q was empty or not provided", flag)
fmt.Fprintln(os.Stderr, err)
return err
Expand Down Expand Up @@ -122,14 +122,14 @@ func _getIps(ipType string, showMsgType bool) {

switch ipType {
case "ipv4":
if showMsgType != true {
if showMsgType {
fmt.Println("IPv4 ranges:")
}
for _, r := range ips.IPv4CIDRs {
fmt.Println(" ", r)
}
case "ipv6":
if showMsgType != true {
if showMsgType {
fmt.Println("IPv6 ranges:")
}
for _, r := range ips.IPv6CIDRs {
Expand Down Expand Up @@ -193,7 +193,7 @@ func pageRules(c *cli.Context) error {
case map[string]interface{}:
s = fmt.Sprintf("%s: %.f - %s", cloudflare.PageRuleActions[a.ID], v["status_code"], v["url"])
case nil:
s = fmt.Sprintf("%s", cloudflare.PageRuleActions[a.ID])
s = cloudflare.PageRuleActions[a.ID]
default:
vs := fmt.Sprintf("%s", v)
s = fmt.Sprintf("%s: %s", cloudflare.PageRuleActions[a.ID], strings.Title(strings.Replace(vs, "_", " ", -1)))
Expand Down
16 changes: 8 additions & 8 deletions cmd/flarectl/zone.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func zoneCreate(c *cli.Context) error {

_, err := api.CreateZone(context.Background(), zone, jumpstart, account, zoneType)
if err != nil {
fmt.Fprintln(os.Stderr, fmt.Sprintf("%s", err))
fmt.Fprintf(os.Stderr, err.Error()+"\n")
return err
}

Expand Down Expand Up @@ -104,7 +104,7 @@ func zoneDelete(c *cli.Context) error {

_, err = api.DeleteZone(context.Background(), zoneID)
if err != nil {
fmt.Fprintln(os.Stderr, fmt.Sprintf("%s", err))
fmt.Fprintf(os.Stderr, err.Error()+"\n")
return err
}

Expand All @@ -123,7 +123,7 @@ func zoneCreateLockdown(c *cli.Context) error {
targets := c.StringSlice("targets")
values := c.StringSlice("values")
if len(targets) != len(values) {
cli.ShowCommandHelp(c, "targets and values does not match")
cli.ShowCommandHelp(c, "targets and values does not match") //nolint
return nil
}
var zonelockdownconfigs = []cloudflare.ZoneLockdownConfig{}
Expand Down Expand Up @@ -161,7 +161,7 @@ func zoneInfo(c *cli.Context) error {
} else if c.String("zone") != "" {
zone = c.String("zone")
} else {
cli.ShowSubcommandHelp(c)
cli.ShowSubcommandHelp(c) //nolint
return nil
}
zones, err := api.ListZones(context.Background(), zone)
Expand Down Expand Up @@ -202,7 +202,7 @@ func zoneSettings(*cli.Context) error {

func zoneCachePurge(c *cli.Context) error {
if err := checkFlags(c, "zone"); err != nil {
cli.ShowSubcommandHelp(c)
cli.ShowSubcommandHelp(c) //nolint
return err
}

Expand Down Expand Up @@ -263,7 +263,7 @@ func zoneRecords(c *cli.Context) error {
} else if c.String("zone") != "" {
zone = c.String("zone")
} else {
cli.ShowSubcommandHelp(c)
cli.ShowSubcommandHelp(c) //nolint
return nil
}

Expand Down Expand Up @@ -318,7 +318,7 @@ func zoneRecords(c *cli.Context) error {
r.Type,
r.Name,
r.Content,
fmt.Sprintf("%s", strconv.FormatBool(*r.Proxied)),
strconv.FormatBool(*r.Proxied),
fmt.Sprintf("%d", r.TTL),
})
}
Expand Down Expand Up @@ -346,7 +346,7 @@ func zoneExport(c *cli.Context) error {
} else if c.String("zone") != "" {
zone = c.String("zone")
} else {
cli.ShowSubcommandHelp(c)
cli.ShowSubcommandHelp(c) //nolint
return nil
}

Expand Down
2 changes: 1 addition & 1 deletion errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (e APIRequestError) Error() string {
for _, err := range e.Errors {
m := ""
if err.Message != "" {
m += fmt.Sprintf("%s", err.Message)
m += err.Message
}

if err.Code != 0 {
Expand Down
7 changes: 3 additions & 4 deletions errors_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cloudflare

import (
"fmt"
"strconv"
"testing"

Expand Down Expand Up @@ -136,7 +135,7 @@ func TestAPIRequestError_ServiceError(t *testing.T) {
}

for name, tc := range tests {
t.Run(fmt.Sprintf("%s", strconv.Itoa(name)), func(t *testing.T) {
t.Run(strconv.Itoa(name), func(t *testing.T) {
got := &APIRequestError{StatusCode: name}
assert.Equal(t, got.ServiceError(), tc.want)
})
Expand All @@ -153,7 +152,7 @@ func TestAPIRequestError_ClientError(t *testing.T) {
}

for name, tc := range tests {
t.Run(fmt.Sprintf("%s", strconv.Itoa(name)), func(t *testing.T) {
t.Run(strconv.Itoa(name), func(t *testing.T) {
got := &APIRequestError{StatusCode: name}
assert.Equal(t, got.ClientError(), tc.want)
})
Expand All @@ -170,7 +169,7 @@ func TestAPIRequestError_ClientRateLimited(t *testing.T) {
}

for name, tc := range tests {
t.Run(fmt.Sprintf("%s", strconv.Itoa(name)), func(t *testing.T) {
t.Run(strconv.Itoa(name), func(t *testing.T) {
got := &APIRequestError{StatusCode: name}
assert.Equal(t, got.ClientRateLimited(), tc.want)
})
Expand Down
5 changes: 2 additions & 3 deletions filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,10 +220,9 @@ func (api *API) DeleteFilters(ctx context.Context, zoneID string, filterIDs []st
//
// API reference: https://developers.cloudflare.com/firewall/api/cf-filters/validation/
func (api *API) ValidateFilterExpression(ctx context.Context, expression string) error {
uri := fmt.Sprintf("/filters/validate-expr")
expressionPayload := FilterValidateExpression{Expression: expression}

_, err := api.makeRequestContext(ctx, http.MethodPost, uri, expressionPayload)
_, err := api.makeRequestContext(ctx, http.MethodPost, "/filters/validate-expr", expressionPayload)
if err != nil {
var filterValidationResponse FilterValidateExpressionResponse

Expand All @@ -232,7 +231,7 @@ func (api *API) ValidateFilterExpression(ctx context.Context, expression string)
return errors.Wrap(jsonErr, errUnmarshalError)
}

if filterValidationResponse.Success != true {
if !filterValidationResponse.Success {
// Unsure why but the API returns `errors` as an array but it only
// ever shows the issue with one problem at a time ¯\_(ツ)_/¯
return errors.Errorf(filterValidationResponse.Errors[0].Message)
Expand Down
16 changes: 0 additions & 16 deletions logpush_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,6 @@ var (
Valid: true,
Message: "",
}
expectedLogpushGetOwnershipChallengeInvalidResponseStruct = LogpushGetOwnershipChallenge{
Filename: "logs/challenge-filename.txt",
Valid: false,
Message: "destination is invalid",
}
expectedUpdatedLogpushJobStruct = LogpushJob{
ID: jobID,
Dataset: "http_requests",
Enabled: true,
Name: "updated.com",
LogpullOptions: "fields=RayID,ClientIP,EdgeStartTimestamp",
DestinationConf: "gs://mybucket/logs",
LastComplete: &testLogpushTimestamp,
LastError: &testLogpushTimestamp,
ErrorMessage: "test",
}
)

func TestLogpushJobs(t *testing.T) {
Expand Down
Loading

0 comments on commit 0a96140

Please sign in to comment.