Update golangci-lint to v2

This commit is contained in:
世界 2025-08-13 22:42:54 +08:00
parent 043a2e7a07
commit 378e39f70c
No known key found for this signature in database
GPG Key ID: CD109927C34A63C4
20 changed files with 67 additions and 61 deletions

View File

@ -28,7 +28,7 @@ jobs:
- name: Setup Go - name: Setup Go
uses: actions/setup-go@v5 uses: actions/setup-go@v5
with: with:
go-version: ^1.25.0 go-version: ~1.24.6
- name: golangci-lint - name: golangci-lint
uses: golangci/golangci-lint-action@v8 uses: golangci/golangci-lint-action@v8
with: with:

View File

@ -1,27 +1,6 @@
linters: version: "2"
disable-all: true
enable:
- gofumpt
- govet
- gci
- staticcheck
- paralleltest
- ineffassign
linters-settings:
gci:
custom-order: true
sections:
- standard
- prefix(github.com/sagernet/)
- default
staticcheck:
checks:
- all
- -SA1003
run: run:
go: "1.23" go: "1.24"
build-tags: build-tags:
- with_gvisor - with_gvisor
- with_quic - with_quic
@ -30,7 +9,51 @@ run:
- with_utls - with_utls
- with_acme - with_acme
- with_clash_api - with_clash_api
linters:
issues: default: none
exclude-dirs: enable:
- govet
- ineffassign
- paralleltest
- staticcheck
settings:
staticcheck:
checks:
- all
- -S1000
- -S1008
- -S1017
- -ST1003
- -QF1001
- -QF1003
- -QF1008
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
paths:
- transport/simple-obfs - transport/simple-obfs
- third_party$
- builtin$
- examples$
formatters:
enable:
- gci
- gofumpt
settings:
gci:
sections:
- standard
- prefix(github.com/sagernet/)
- default
custom-order: true
exclusions:
generated: lax
paths:
- transport/simple-obfs
- third_party$
- builtin$
- examples$

View File

@ -45,7 +45,7 @@ lint:
GOOS=freebsd golangci-lint run ./... GOOS=freebsd golangci-lint run ./...
lint_install: lint_install:
go install -v github.com/golangci/golangci-lint/cmd/golangci-lint@latest go install -v github.com/golangci/golangci-lint/v2/cmd/golangci-lint@latest
proto: proto:
@go run ./cmd/internal/protogen @go run ./cmd/internal/protogen

View File

@ -135,8 +135,7 @@ func ExtendContext(ctx context.Context) (context.Context, *InboundContext) {
func OverrideContext(ctx context.Context) context.Context { func OverrideContext(ctx context.Context) context.Context {
if metadata := ContextFrom(ctx); metadata != nil { if metadata := ContextFrom(ctx); metadata != nil {
var newMetadata InboundContext newMetadata := *metadata
newMetadata = *metadata
return WithContext(ctx, &newMetadata) return WithContext(ctx, &newMetadata)
} }
return ctx return ctx

View File

@ -151,9 +151,7 @@ func testOnce(boxPath string, stackName string, mtu int, multiThread bool, flags
var sudoArgs []string var sudoArgs []string
if len(flags) > 0 { if len(flags) > 0 {
sudoArgs = append(sudoArgs, "env") sudoArgs = append(sudoArgs, "env")
for _, flag := range flags { sudoArgs = append(sudoArgs, flags...)
sudoArgs = append(sudoArgs, flag)
}
} }
sudoArgs = append(sudoArgs, boxPath, "run", "-c", tempConfig.Name()) sudoArgs = append(sudoArgs, boxPath, "run", "-c", tempConfig.Name())
boxProcess := shell.Exec("sudo", sudoArgs...) boxProcess := shell.Exec("sudo", sudoArgs...)

View File

@ -271,7 +271,7 @@ func (d *DefaultDialer) DialParallelInterface(ctx context.Context, network strin
} else { } else {
dialer = d.udpDialer4 dialer = d.udpDialer4
} }
fastFallback := time.Now().Sub(d.networkLastFallback.Load()) < C.TCPTimeout fastFallback := time.Since(d.networkLastFallback.Load()) < C.TCPTimeout
var ( var (
conn net.Conn conn net.Conn
isPrimary bool isPrimary bool

View File

@ -17,8 +17,5 @@ var uQUICChrome115 = &ja3.ClientHello{
} }
func maybeUQUIC(fingerprint *ja3.ClientHello) bool { func maybeUQUIC(fingerprint *ja3.ClientHello) bool {
if uQUICChrome115.Equals(fingerprint, true) { return !uQUICChrome115.Equals(fingerprint, true)
return true
}
return false
} }

View File

@ -125,7 +125,7 @@ func (s *ECHClientConfig) ClientHandshake(ctx context.Context, conn net.Conn) (a
func (s *ECHClientConfig) fetchAndHandshake(ctx context.Context, conn net.Conn) (aTLS.Conn, error) { func (s *ECHClientConfig) fetchAndHandshake(ctx context.Context, conn net.Conn) (aTLS.Conn, error) {
s.access.Lock() s.access.Lock()
defer s.access.Unlock() defer s.access.Unlock()
if len(s.ECHConfigList()) == 0 || s.lastTTL == 0 || time.Now().Sub(s.lastUpdate) > s.lastTTL { if len(s.ECHConfigList()) == 0 || s.lastTTL == 0 || time.Since(s.lastUpdate) > s.lastTTL {
message := &mDNS.Msg{ message := &mDNS.Msg{
MsgHdr: mDNS.MsgHdr{ MsgHdr: mDNS.MsgHdr{
RecursionDesired: true, RecursionDesired: true,

View File

@ -104,7 +104,7 @@ func (c *dnsConfig) serverOffset() uint32 {
return 0 return 0
} }
func (conf *dnsConfig) nameList(name string) []string { func (c *dnsConfig) nameList(name string) []string {
l := len(name) l := len(name)
rooted := l > 0 && name[l-1] == '.' rooted := l > 0 && name[l-1] == '.'
if l > 254 || l == 254 && !rooted { if l > 254 || l == 254 && !rooted {
@ -118,15 +118,15 @@ func (conf *dnsConfig) nameList(name string) []string {
return []string{name} return []string{name}
} }
hasNdots := strings.Count(name, ".") >= conf.ndots hasNdots := strings.Count(name, ".") >= c.ndots
name += "." name += "."
// l++ // l++
names := make([]string, 0, 1+len(conf.search)) names := make([]string, 0, 1+len(c.search))
if hasNdots && !avoidDNS(name) { if hasNdots && !avoidDNS(name) {
names = append(names, name) names = append(names, name)
} }
for _, suffix := range conf.search { for _, suffix := range c.search {
fqdn := name + suffix fqdn := name + suffix
if !avoidDNS(fqdn) && len(fqdn) <= 254 { if !avoidDNS(fqdn) && len(fqdn) <= 254 {
names = append(names, fqdn) names = append(names, fqdn)

View File

@ -62,10 +62,7 @@ func (s *CommandServer) handleURLTest(conn net.Conn) error {
return false return false
} }
_, isGroup := it.(adapter.OutboundGroup) _, isGroup := it.(adapter.OutboundGroup)
if isGroup { return !isGroup
return false
}
return true
}) })
b, _ := batch.New(serviceNow.ctx, batch.WithConcurrencyNum[any](10)) b, _ := batch.New(serviceNow.ctx, batch.WithConcurrencyNum[any](10))
for _, detour := range outbounds { for _, detour := range outbounds {

View File

@ -192,7 +192,7 @@ func (s *StatsService) GetSysStats(ctx context.Context, request *SysStatsRequest
var rtm runtime.MemStats var rtm runtime.MemStats
runtime.ReadMemStats(&rtm) runtime.ReadMemStats(&rtm)
response := &SysStatsResponse{ response := &SysStatsResponse{
Uptime: uint32(time.Now().Sub(s.createdAt).Seconds()), Uptime: uint32(time.Since(s.createdAt).Seconds()),
NumGoroutine: uint32(runtime.NumGoroutine()), NumGoroutine: uint32(runtime.NumGoroutine()),
Alloc: rtm.Alloc, Alloc: rtm.Alloc,
TotalAlloc: rtm.TotalAlloc, TotalAlloc: rtm.TotalAlloc,

View File

@ -100,7 +100,6 @@ func rewriteRcodeAction(rcodeMap map[string]int, ruleAction *DNSRuleAction) {
} }
ruleAction.Action = C.RuleActionTypePredefined ruleAction.Action = C.RuleActionTypePredefined
ruleAction.PredefinedOptions.Rcode = common.Ptr(DNSRCode(rcode)) ruleAction.PredefinedOptions.Rcode = common.Ptr(DNSRCode(rcode))
return
} }
type DNSClientOptions struct { type DNSClientOptions struct {

View File

@ -313,7 +313,7 @@ func (g *URLTestGroup) Select(network string) (adapter.Outbound, bool) {
} }
func (g *URLTestGroup) loopCheck() { func (g *URLTestGroup) loopCheck() {
if time.Now().Sub(g.lastActive.Load()) > g.interval { if time.Since(g.lastActive.Load()) > g.interval {
g.lastActive.Store(time.Now()) g.lastActive.Store(time.Now())
g.CheckOutbounds(false) g.CheckOutbounds(false)
} }
@ -323,7 +323,7 @@ func (g *URLTestGroup) loopCheck() {
return return
case <-g.ticker.C: case <-g.ticker.C:
} }
if time.Now().Sub(g.lastActive.Load()) > g.idleTimeout { if time.Since(g.lastActive.Load()) > g.idleTimeout {
g.access.Lock() g.access.Lock()
g.ticker.Stop() g.ticker.Stop()
g.ticker = nil g.ticker = nil
@ -360,7 +360,7 @@ func (g *URLTestGroup) urlTest(ctx context.Context, force bool) (map[string]uint
continue continue
} }
history := g.history.LoadURLTestHistory(realTag) history := g.history.LoadURLTestHistory(realTag)
if !force && history != nil && time.Now().Sub(history.Time) < g.interval { if !force && history != nil && time.Since(history.Time) < g.interval {
continue continue
} }
checked[realTag] = true checked[realTag] = true

View File

@ -128,7 +128,6 @@ func (h *Outbound) InterfaceUpdated() {
if h.multiplexDialer != nil { if h.multiplexDialer != nil {
h.multiplexDialer.Reset() h.multiplexDialer.Reset()
} }
return
} }
func (h *Outbound) Close() error { func (h *Outbound) Close() error {

View File

@ -180,7 +180,6 @@ func (s *Outbound) connect() (*ssh.Client, error) {
func (s *Outbound) InterfaceUpdated() { func (s *Outbound) InterfaceUpdated() {
common.Close(s.clientConn) common.Close(s.clientConn)
return
} }
func (s *Outbound) Close() error { func (s *Outbound) Close() error {

View File

@ -105,7 +105,6 @@ func (h *Outbound) InterfaceUpdated() {
if h.multiplexDialer != nil { if h.multiplexDialer != nil {
h.multiplexDialer.Reset() h.multiplexDialer.Reset()
} }
return
} }
func (h *Outbound) Close() error { func (h *Outbound) Close() error {

View File

@ -124,7 +124,6 @@ func (h *Outbound) InterfaceUpdated() {
if h.multiplexDialer != nil { if h.multiplexDialer != nil {
h.multiplexDialer.Reset() h.multiplexDialer.Reset()
} }
return
} }
func (h *Outbound) Close() error { func (h *Outbound) Close() error {

View File

@ -108,7 +108,6 @@ func (h *Outbound) InterfaceUpdated() {
if h.multiplexDialer != nil { if h.multiplexDialer != nil {
h.multiplexDialer.Reset() h.multiplexDialer.Reset()
} }
return
} }
func (h *Outbound) Close() error { func (h *Outbound) Close() error {

View File

@ -178,7 +178,6 @@ func (s *TrafficManager) ReadUsers(users []*UserObject) {
for _, user := range users { for _, user := range users {
s.readUser(user) s.readUser(user)
} }
return
} }
func (s *TrafficManager) ReadGlobal() ( func (s *TrafficManager) ReadGlobal() (

View File

@ -72,8 +72,7 @@ func (c *Client) offerNew() (quic.Connection, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
var packetConn net.PacketConn packetConn := bufio.NewUnbindPacketConn(udpConn)
packetConn = bufio.NewUnbindPacketConn(udpConn)
quicConn, err := qtls.Dial(c.ctx, packetConn, udpConn.RemoteAddr(), c.tlsConfig, c.quicConfig) quicConn, err := qtls.Dial(c.ctx, packetConn, udpConn.RemoteAddr(), c.tlsConfig, c.quicConfig)
if err != nil { if err != nil {
packetConn.Close() packetConn.Close()