Skip to content

Commit

Permalink
Merge pull request #18973 from mmorel-35/[email protected]
Browse files Browse the repository at this point in the history
fix: enable gosimple linter
  • Loading branch information
ahrtr authored Dec 4, 2024
2 parents 2b32307 + 647f162 commit da807d7
Show file tree
Hide file tree
Showing 15 changed files with 17 additions and 25 deletions.
2 changes: 1 addition & 1 deletion etcdctl/ctlv3/command/defrag_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func defragCommandFunc(cmd *cobra.Command, args []string) {
ctx, cancel := commandCtx(cmd)
start := time.Now()
_, err := c.Defragment(ctx, ep)
d := time.Now().Sub(start)
d := time.Since(start)
cancel()
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to defragment etcd member[%s]. took %s. (%v)\n", ep, d.String(), err)
Expand Down
1 change: 0 additions & 1 deletion etcdctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,4 @@ import (

func main() {
ctlv3.MustStart()
return
}
2 changes: 1 addition & 1 deletion server/etcdserver/api/v3discovery/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ func (cls *clusterInfo) add(memberKey, memberValue string, rev int64) error {
return errors.New("invalid peer registry key")
}

if strings.IndexRune(memberValue, '=') == -1 {
if !strings.ContainsRune(memberValue, '=') {
// It must be in the format "member1=http://127.0.0.1:2380".
return errors.New("invalid peer info returned from discovery service")
}
Expand Down
3 changes: 1 addition & 2 deletions server/etcdserver/cluster_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -433,8 +433,7 @@ func convertToClusterVersion(v string) (*semver.Version, error) {
}

func GetMembershipInfoInV2Format(lg *zap.Logger, cl *membership.RaftCluster) []byte {
var st v2store.Store
st = v2store.New(StoreClusterPrefix, StoreKeysPrefix)
st := v2store.New(StoreClusterPrefix, StoreKeysPrefix)
cl.Store(st)
d, err := st.SaveNoCopy()
if err != nil {
Expand Down
1 change: 0 additions & 1 deletion server/etcdserver/corrupt.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,6 @@ func (cm *corruptionChecker) CompactHashCheck() {
}
}
cm.lg.Info("finished compaction hash check", zap.Int("number-of-hashes-checked", len(hashes)))
return
}

// check peers hash and raise alarms if detected corruption.
Expand Down
4 changes: 1 addition & 3 deletions server/storage/mvcc/hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,7 @@ func (s *hashStorage) Hashes() []KeyValueHash {
s.hashMu.RLock()
// Copy out hashes under lock just to be safe
hashes := make([]KeyValueHash, 0, len(s.hashes))
for _, hash := range s.hashes {
hashes = append(hashes, hash)
}
hashes = append(hashes, s.hashes...)
s.hashMu.RUnlock()
return hashes
}
5 changes: 1 addition & 4 deletions server/storage/wal/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,7 @@ func visitMessage(m protoreflect.Message, visitor Visitor) error {
case protoreflect.EnumNumber:
err = visitEnumNumber(fd.Enum(), m, visitor)
}
if err != nil {
return false
}
return true
return err == nil
})
return err
}
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/v2store_deprecation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,11 @@ func assertSnapshotsMatch(t testing.TB, firstDataDir, secondDataDir string, patc
func assertMembershipEqual(t testing.TB, firstStore v2store.Store, secondStore v2store.Store) {
rc1 := membership.NewCluster(zaptest.NewLogger(t))
rc1.SetStore(firstStore)
rc1.Recover(func(lg *zap.Logger, v *semver.Version) { return })
rc1.Recover(func(lg *zap.Logger, v *semver.Version) {})

rc2 := membership.NewCluster(zaptest.NewLogger(t))
rc2.SetStore(secondStore)
rc2.Recover(func(lg *zap.Logger, v *semver.Version) { return })
rc2.Recover(func(lg *zap.Logger, v *semver.Version) {})

// membership should match
if !reflect.DeepEqual(rc1.Members(), rc2.Members()) {
Expand Down
1 change: 0 additions & 1 deletion tests/e2e/v3_curl_maintenance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ func testCurlV3MaintenanceStatus(cx ctlCtx) {
}
}

require.Contains(cx.t, resp, "version")
require.Equal(cx.t, version.Version, resp["version"])
}

Expand Down
1 change: 0 additions & 1 deletion tests/integration/clientv3/concurrency/example_stm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ func ExampleSTM_apply() {
// write back
stm.Put(fromK, fmt.Sprintf("%d", fromInt))
stm.Put(toK, fmt.Sprintf("%d", toInt))
return
}

// concurrently exchange values between accounts
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/revision_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ func silenceConnectionErrors(err error) error {
}
s := status.Convert(err)
for _, msg := range connectionErrorMessages {
if strings.Index(s.Message(), msg) != -1 {
if strings.Contains(s.Message(), msg) {
return nil
}
}
Expand Down
6 changes: 3 additions & 3 deletions tests/robustness/model/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func describeEtcdResponse(request EtcdRequest, response MaybeEtcdResponse) strin
if response.PersistedRevision != 0 {
return fmt.Sprintf("unknown, rev: %d", response.PersistedRevision)
}
return fmt.Sprintf("unknown")
return "unknown"
}
switch request.Type {
case Range:
Expand Down Expand Up @@ -74,7 +74,7 @@ func describeEtcdRequest(request EtcdRequest) string {
case LeaseRevoke:
return fmt.Sprintf("leaseRevoke(%d)", request.LeaseRevoke.LeaseID)
case Defragment:
return fmt.Sprintf("defragment()")
return "defragment()"
case Compact:
return fmt.Sprintf("compact(%d)", request.Compact.Revision)
default:
Expand Down Expand Up @@ -182,7 +182,7 @@ func describeEtcdOperationResponse(op EtcdOperation, resp EtcdOperationResult) s
case RangeOperation:
return describeRangeResponse(op.Range, resp.RangeResponse)
case PutOperation:
return fmt.Sprintf("ok")
return "ok"
case DeleteOperation:
return fmt.Sprintf("deleted: %d", resp.Deleted)
default:
Expand Down
4 changes: 1 addition & 3 deletions tests/robustness/model/replay.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ func NewReplay(persistedRequests []EtcdRequest) *EtcdReplay {
if state.Revision != newState.Revision {
revisionToEtcdState = append(revisionToEtcdState, newState)
}
for _, e := range toWatchEvents(&state, request, response) {
events = append(events, e)
}
events = append(events, toWatchEvents(&state, request, response)...)
state = newState
}
return &EtcdReplay{
Expand Down
2 changes: 1 addition & 1 deletion tests/robustness/traffic/limiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func (c *concurrencyLimiter) Take() bool {

func (c *concurrencyLimiter) Return() {
select {
case _ = <-c.ch:
case <-c.ch:
default:
panic("Call to Return() without a successful Take")
}
Expand Down
4 changes: 4 additions & 0 deletions tools/.golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ issues:
# exclude ineffassing linter for generated files for conversion
- path: conversion\.go
linters: [ineffassign]
- text: "S1000" # TODO: Fix me
linters:
- gosimple
exclude-files:
- ^zz_generated.*
linters:
Expand All @@ -21,6 +24,7 @@ linters:
- errorlint
- gofumpt
- goimports
- gosimple
- ineffassign
- nakedret
- revive
Expand Down

0 comments on commit da807d7

Please sign in to comment.