Skip to content

Commit a769ed6

Browse files
authored
lint: fix staticcheck QF issues (#8524)
This PR fixes these staticcheck lint issues: This partially addresses the TODO comment: https://github.com/letsencrypt/boulder/blob/be957c2242aa543549f28d41048ea3abee30a20b/.golangci.yml#L67-L70
1 parent f3e973a commit a769ed6

File tree

8 files changed

+15
-24
lines changed

8 files changed

+15
-24
lines changed

.golangci.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,7 @@ linters:
7575
- -ST1003 # Poorly chosen identifier
7676
- -ST1005 # Incorrectly formatted error string
7777
- -QF1001 # Could apply De Morgan's law
78-
- -QF1003 # Could use tagged switch
79-
- -QF1004 # Could use strings.Split instead
80-
- -QF1007 # Could merge conditional assignment into variable declaration
8178
- -QF1008 # Could remove embedded field from selector
82-
- -QF1009 # Probably want to use time.Time.Equal
83-
- -QF1012 # Use fmt.Fprintf(...) instead of Write(fmt.Sprintf(...))
8479
exclusions:
8580
presets:
8681
- std-error-handling

log/log.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ func (w *bothWriter) logAtLevel(level syslog.Priority, msg string, a ...any) {
186186

187187
// Since messages are delimited by newlines, we have to escape any internal or
188188
// trailing newlines before generating the checksum or outputting the message.
189-
msg = strings.Replace(msg, "\n", "\\n", -1)
189+
msg = strings.ReplaceAll(msg, "\n", "\\n")
190190

191191
w.Lock()
192192
defer w.Unlock()
@@ -232,7 +232,7 @@ func (w *stdoutWriter) logAtLevel(level syslog.Priority, msg string, a ...any) {
232232
msg = fmt.Sprintf(msg, a...)
233233
}
234234

235-
msg = strings.Replace(msg, "\n", "\\n", -1)
235+
msg = strings.ReplaceAll(msg, "\n", "\\n")
236236

237237
var color string
238238
var reset string

mocks/sa.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,10 @@ func (sa *StorageAuthorityReadOnly) FQDNSetExists(_ context.Context, _ *sapb.FQD
246246

247247
// GetOrder is a mock
248248
func (sa *StorageAuthorityReadOnly) GetOrder(_ context.Context, req *sapb.OrderRequest, _ ...grpc.CallOption) (*corepb.Order, error) {
249-
if req.Id == 2 {
249+
switch req.Id {
250+
case 2:
250251
return nil, berrors.NotFoundError("bad")
251-
} else if req.Id == 3 {
252+
case 3:
252253
return nil, errors.New("very bad")
253254
}
254255

policy/pa.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ func ValidEmail(address string) error {
388388
if err != nil {
389389
return berrors.InvalidEmailError("unable to parse email address")
390390
}
391-
splitEmail := strings.SplitN(email.Address, "@", -1)
391+
splitEmail := strings.Split(email.Address, "@")
392392
domain := strings.ToLower(splitEmail[len(splitEmail)-1])
393393
err = validNonWildcardDomain(domain)
394394
if err != nil {

publisher/publisher_test.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,7 @@ func logSrv(k *ecdsa.PrivateKey) *testLogSrv {
6767
if err != nil {
6868
return
6969
}
70-
precert := false
71-
if r.URL.Path == "/ct/v1/add-pre-chain" {
72-
precert = true
73-
}
70+
precert := r.URL.Path == "/ct/v1/add-pre-chain"
7471
sct := CreateTestingSignedSCT(jsonReq.Chain, k, precert, time.Now())
7572
fmt.Fprint(w, string(sct))
7673
atomic.AddInt64(&testLog.submissions, 1)
@@ -92,10 +89,7 @@ func lyingLogSrv(k *ecdsa.PrivateKey, timestamp time.Time) *testLogSrv {
9289
if err != nil {
9390
return
9491
}
95-
precert := false
96-
if r.URL.Path == "/ct/v1/add-pre-chain" {
97-
precert = true
98-
}
92+
precert := r.URL.Path == "/ct/v1/add-pre-chain"
9993
sct := CreateTestingSignedSCT(jsonReq.Chain, k, precert, timestamp)
10094
fmt.Fprint(w, string(sct))
10195
atomic.AddInt64(&testLog.submissions, 1)

ra/ra_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ func TestPerformValidationSuccess(t *testing.T) {
667667

668668
// Check that validated timestamp was recorded, stored, and retrieved
669669
expectedValidated := fc.Now()
670-
test.Assert(t, *challenge.Validated == expectedValidated, "Validated timestamp incorrect or missing")
670+
test.AssertEquals(t, *challenge.Validated, expectedValidated)
671671
}
672672
}
673673

@@ -879,7 +879,7 @@ func TestPerformValidationVAError(t *testing.T) {
879879

880880
// Check that validated timestamp was recorded, stored, and retrieved
881881
expectedValidated := fc.Now()
882-
test.Assert(t, *challenge.Validated == expectedValidated, "Validated timestamp incorrect or missing")
882+
test.AssertEquals(t, *challenge.Validated, expectedValidated)
883883
}
884884

885885
func TestCertificateKeyNotEqualAccountKey(t *testing.T) {

test/certs/webpki.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func main() {
107107
// template files) are meaningful and are consumed by aia-test-srv. If
108108
// you change the structure of these file names, you will need to change
109109
// aia-test-srv as well to recognize and consume the resulting files.
110-
fileName := strings.Replace(name, " ", "-", -1)
110+
fileName := strings.ReplaceAll(name, " ", "-")
111111

112112
// Create SoftHSM slot
113113
keySlot, err := createSlot(name)

test/s3-test-srv/main.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@ type s3TestSrv struct {
2222
}
2323

2424
func (srv *s3TestSrv) handleS3(w http.ResponseWriter, r *http.Request) {
25-
if r.Method == "PUT" {
25+
switch r.Method {
26+
case "PUT":
2627
srv.handleUpload(w, r)
27-
} else if r.Method == "GET" {
28+
case "GET":
2829
srv.handleDownload(w, r)
29-
} else {
30+
default:
3031
w.WriteHeader(http.StatusMethodNotAllowed)
3132
}
3233
}

0 commit comments

Comments
 (0)