Skip to content

Commit

Permalink
chore: enable early-return and unnecessary-stmt and useless-break fro…
Browse files Browse the repository at this point in the history
…m revive (#8100)
  • Loading branch information
mmorel-35 authored Feb 20, 2025
1 parent c7db760 commit c75fc8e
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 17 deletions.
3 changes: 1 addition & 2 deletions clientconn.go
Original file line number Diff line number Diff line change
Expand Up @@ -1231,8 +1231,7 @@ func (ac *addrConn) updateConnectivityState(s connectivity.State, lastErr error)
// adjustParams updates parameters used to create transports upon
// receiving a GoAway.
func (ac *addrConn) adjustParams(r transport.GoAwayReason) {
switch r {
case transport.GoAwayTooManyPings:
if r == transport.GoAwayTooManyPings {
v := 2 * ac.dopts.copts.KeepaliveParams.Time
ac.cc.mu.Lock()
if v > ac.cc.keepaliveParams.Time {
Expand Down
3 changes: 1 addition & 2 deletions internal/stubserver/stubserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,7 @@ func (ss *StubServer) setupServer(sopts ...grpc.ServerOption) (net.Listener, err
ss.S = grpc.NewServer(sopts...)
}
for _, so := range sopts {
switch x := so.(type) {
case *registerServiceServerOption:
if x, ok := so.(*registerServiceServerOption); ok {
x.f(ss.S)
}
}
Expand Down
3 changes: 1 addition & 2 deletions internal/transport/http2_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1390,8 +1390,7 @@ func (t *http2Client) handleGoAway(f *http2.GoAwayFrame) error {
// the caller.
func (t *http2Client) setGoAwayReason(f *http2.GoAwayFrame) {
t.goAwayReason = GoAwayNoReason
switch f.ErrCode {
case http2.ErrCodeEnhanceYourCalm:
if f.ErrCode == http2.ErrCodeEnhanceYourCalm {
if string(f.DebugData()) == "too_many_pings" {
t.goAwayReason = GoAwayTooManyPings
}
Expand Down
5 changes: 2 additions & 3 deletions profiling/cmd/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,10 @@ func exactlyOneOf(opts ...bool) bool {
continue
}

if first {
first = false
} else {
if !first {
return false
}
first = false
}

return !first
Expand Down
37 changes: 32 additions & 5 deletions scripts/revive.toml
Original file line number Diff line number Diff line change
@@ -1,33 +1,60 @@
# Enabled rules
[rule.blank-imports]

[rule.context-as-argument]

[rule.context-keys-type]

[rule.dot-imports]

[rule.errorf]

[rule.error-return]

[rule.error-strings]

[rule.error-naming]

[rule.exported]

[rule.increment-decrement]

[rule.indent-error-flow]
arguments = ["preserveScope"]

[rule.package-comments]

[rule.range]

[rule.receiver-naming]

[rule.superfluous-else]
arguments = ["preserveScope"]

[rule.time-naming]
[rule.var-naming]

[rule.unexported-return]
[rule.unused-parameter]

[rule.unnecessary-stmt]

[rule.unreachable-code]
[rule.var-declaration]

[rule.unused-parameter]

[rule.use-any]

[rule.useless-break]

[rule.var-declaration]

[rule.var-naming]

# Disabled rules
[rule.empty-block] # Disabled to allow intentional no-op blocks (e.g., channel draining).
Disabled = true

[rule.import-shadowing] # Disabled to allow intentional reuse of variable names that are the same as package imports.
Disabled = true

[rule.redefines-builtin-id] # Disabled to allow intentional reuse of variable names that are the same as built-in functions.
Disabled = true


1 change: 0 additions & 1 deletion test/bufconn/bufconn.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ func (l *Listener) Close() error {
select {
case <-l.done:
// Already closed.
break
default:
close(l.done)
}
Expand Down
3 changes: 1 addition & 2 deletions test/end2end_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -610,8 +610,7 @@ func (te *test) listenAndServe(ts testgrpc.TestServiceServer, listen func(networ
sopts = append(sopts, grpc.InitialConnWindowSize(te.serverInitialConnWindowSize))
}
la := ":0"
switch te.e.network {
case "unix":
if te.e.network == "unix" {
la = "/tmp/testsock" + fmt.Sprintf("%d", time.Now().UnixNano())
syscall.Unlink(la)
}
Expand Down

0 comments on commit c75fc8e

Please sign in to comment.