diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index abeaa4bc..0a8cbd1a 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -28,7 +28,7 @@ jobs: - name: Setup Go uses: actions/setup-go@v5 with: - go-version: ^1.25.0 + go-version: ~1.24.6 - name: golangci-lint uses: golangci/golangci-lint-action@v8 with: diff --git a/.golangci.yml b/.golangci.yml index 9cb20ee8..de2aa5a6 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,27 +1,6 @@ -linters: - 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 - +version: "2" run: - go: "1.23" + go: "1.24" build-tags: - with_gvisor - with_quic @@ -30,7 +9,51 @@ run: - with_utls - with_acme - with_clash_api - -issues: - exclude-dirs: - - transport/simple-obfs +linters: + default: none + 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 + - 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$ diff --git a/Makefile b/Makefile index 00af283e..43f93c8c 100644 --- a/Makefile +++ b/Makefile @@ -45,7 +45,7 @@ lint: GOOS=freebsd golangci-lint run ./... 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: @go run ./cmd/internal/protogen diff --git a/adapter/inbound.go b/adapter/inbound.go index 0de4c799..edba8447 100644 --- a/adapter/inbound.go +++ b/adapter/inbound.go @@ -135,8 +135,7 @@ func ExtendContext(ctx context.Context) (context.Context, *InboundContext) { func OverrideContext(ctx context.Context) context.Context { if metadata := ContextFrom(ctx); metadata != nil { - var newMetadata InboundContext - newMetadata = *metadata + newMetadata := *metadata return WithContext(ctx, &newMetadata) } return ctx diff --git a/cmd/internal/tun_bench/main.go b/cmd/internal/tun_bench/main.go index abad8c34..e62841dc 100644 --- a/cmd/internal/tun_bench/main.go +++ b/cmd/internal/tun_bench/main.go @@ -151,9 +151,7 @@ func testOnce(boxPath string, stackName string, mtu int, multiThread bool, flags var sudoArgs []string if len(flags) > 0 { sudoArgs = append(sudoArgs, "env") - for _, flag := range flags { - sudoArgs = append(sudoArgs, flag) - } + sudoArgs = append(sudoArgs, flags...) } sudoArgs = append(sudoArgs, boxPath, "run", "-c", tempConfig.Name()) boxProcess := shell.Exec("sudo", sudoArgs...) diff --git a/common/dialer/default.go b/common/dialer/default.go index 4b9cf71c..5337934a 100644 --- a/common/dialer/default.go +++ b/common/dialer/default.go @@ -271,7 +271,7 @@ func (d *DefaultDialer) DialParallelInterface(ctx context.Context, network strin } else { dialer = d.udpDialer4 } - fastFallback := time.Now().Sub(d.networkLastFallback.Load()) < C.TCPTimeout + fastFallback := time.Since(d.networkLastFallback.Load()) < C.TCPTimeout var ( conn net.Conn isPrimary bool diff --git a/common/sniff/quic_blacklist.go b/common/sniff/quic_blacklist.go index 7d5f91e7..d5ff7bcf 100644 --- a/common/sniff/quic_blacklist.go +++ b/common/sniff/quic_blacklist.go @@ -17,8 +17,5 @@ var uQUICChrome115 = &ja3.ClientHello{ } func maybeUQUIC(fingerprint *ja3.ClientHello) bool { - if uQUICChrome115.Equals(fingerprint, true) { - return true - } - return false + return !uQUICChrome115.Equals(fingerprint, true) } diff --git a/common/tls/ech.go b/common/tls/ech.go index f4434604..830a8d08 100644 --- a/common/tls/ech.go +++ b/common/tls/ech.go @@ -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) { s.access.Lock() 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{ MsgHdr: mDNS.MsgHdr{ RecursionDesired: true, diff --git a/dns/transport/local/resolv.go b/dns/transport/local/resolv.go index 754d4539..afe679a2 100644 --- a/dns/transport/local/resolv.go +++ b/dns/transport/local/resolv.go @@ -104,7 +104,7 @@ func (c *dnsConfig) serverOffset() uint32 { return 0 } -func (conf *dnsConfig) nameList(name string) []string { +func (c *dnsConfig) nameList(name string) []string { l := len(name) rooted := l > 0 && name[l-1] == '.' if l > 254 || l == 254 && !rooted { @@ -118,15 +118,15 @@ func (conf *dnsConfig) nameList(name string) []string { return []string{name} } - hasNdots := strings.Count(name, ".") >= conf.ndots + hasNdots := strings.Count(name, ".") >= c.ndots name += "." // l++ - names := make([]string, 0, 1+len(conf.search)) + names := make([]string, 0, 1+len(c.search)) if hasNdots && !avoidDNS(name) { names = append(names, name) } - for _, suffix := range conf.search { + for _, suffix := range c.search { fqdn := name + suffix if !avoidDNS(fqdn) && len(fqdn) <= 254 { names = append(names, fqdn) diff --git a/experimental/libbox/command_urltest.go b/experimental/libbox/command_urltest.go index 5dcb3d67..907d1699 100644 --- a/experimental/libbox/command_urltest.go +++ b/experimental/libbox/command_urltest.go @@ -62,10 +62,7 @@ func (s *CommandServer) handleURLTest(conn net.Conn) error { return false } _, isGroup := it.(adapter.OutboundGroup) - if isGroup { - return false - } - return true + return !isGroup }) b, _ := batch.New(serviceNow.ctx, batch.WithConcurrencyNum[any](10)) for _, detour := range outbounds { diff --git a/experimental/v2rayapi/stats.go b/experimental/v2rayapi/stats.go index 6c44518f..a85e190f 100644 --- a/experimental/v2rayapi/stats.go +++ b/experimental/v2rayapi/stats.go @@ -192,7 +192,7 @@ func (s *StatsService) GetSysStats(ctx context.Context, request *SysStatsRequest var rtm runtime.MemStats runtime.ReadMemStats(&rtm) response := &SysStatsResponse{ - Uptime: uint32(time.Now().Sub(s.createdAt).Seconds()), + Uptime: uint32(time.Since(s.createdAt).Seconds()), NumGoroutine: uint32(runtime.NumGoroutine()), Alloc: rtm.Alloc, TotalAlloc: rtm.TotalAlloc, diff --git a/option/dns.go b/option/dns.go index 0886dd64..422d7b3b 100644 --- a/option/dns.go +++ b/option/dns.go @@ -100,7 +100,6 @@ func rewriteRcodeAction(rcodeMap map[string]int, ruleAction *DNSRuleAction) { } ruleAction.Action = C.RuleActionTypePredefined ruleAction.PredefinedOptions.Rcode = common.Ptr(DNSRCode(rcode)) - return } type DNSClientOptions struct { diff --git a/protocol/group/urltest.go b/protocol/group/urltest.go index f44698e1..719f4a2c 100644 --- a/protocol/group/urltest.go +++ b/protocol/group/urltest.go @@ -313,7 +313,7 @@ func (g *URLTestGroup) Select(network string) (adapter.Outbound, bool) { } 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.CheckOutbounds(false) } @@ -323,7 +323,7 @@ func (g *URLTestGroup) loopCheck() { return 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.ticker.Stop() g.ticker = nil @@ -360,7 +360,7 @@ func (g *URLTestGroup) urlTest(ctx context.Context, force bool) (map[string]uint continue } 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 } checked[realTag] = true diff --git a/protocol/shadowsocks/outbound.go b/protocol/shadowsocks/outbound.go index 875c9e69..9b9d9252 100644 --- a/protocol/shadowsocks/outbound.go +++ b/protocol/shadowsocks/outbound.go @@ -128,7 +128,6 @@ func (h *Outbound) InterfaceUpdated() { if h.multiplexDialer != nil { h.multiplexDialer.Reset() } - return } func (h *Outbound) Close() error { diff --git a/protocol/ssh/outbound.go b/protocol/ssh/outbound.go index aeb43d34..b2f96807 100644 --- a/protocol/ssh/outbound.go +++ b/protocol/ssh/outbound.go @@ -180,7 +180,6 @@ func (s *Outbound) connect() (*ssh.Client, error) { func (s *Outbound) InterfaceUpdated() { common.Close(s.clientConn) - return } func (s *Outbound) Close() error { diff --git a/protocol/trojan/outbound.go b/protocol/trojan/outbound.go index 37a6933c..cd290386 100644 --- a/protocol/trojan/outbound.go +++ b/protocol/trojan/outbound.go @@ -105,7 +105,6 @@ func (h *Outbound) InterfaceUpdated() { if h.multiplexDialer != nil { h.multiplexDialer.Reset() } - return } func (h *Outbound) Close() error { diff --git a/protocol/vless/outbound.go b/protocol/vless/outbound.go index e0208be9..b95a36f7 100644 --- a/protocol/vless/outbound.go +++ b/protocol/vless/outbound.go @@ -124,7 +124,6 @@ func (h *Outbound) InterfaceUpdated() { if h.multiplexDialer != nil { h.multiplexDialer.Reset() } - return } func (h *Outbound) Close() error { diff --git a/protocol/vmess/outbound.go b/protocol/vmess/outbound.go index be05990e..bf76ab3d 100644 --- a/protocol/vmess/outbound.go +++ b/protocol/vmess/outbound.go @@ -108,7 +108,6 @@ func (h *Outbound) InterfaceUpdated() { if h.multiplexDialer != nil { h.multiplexDialer.Reset() } - return } func (h *Outbound) Close() error { diff --git a/service/ssmapi/traffic.go b/service/ssmapi/traffic.go index 23a034c1..df1b04b1 100644 --- a/service/ssmapi/traffic.go +++ b/service/ssmapi/traffic.go @@ -178,7 +178,6 @@ func (s *TrafficManager) ReadUsers(users []*UserObject) { for _, user := range users { s.readUser(user) } - return } func (s *TrafficManager) ReadGlobal() ( diff --git a/transport/v2rayquic/client.go b/transport/v2rayquic/client.go index a1c3e3a6..f9556211 100644 --- a/transport/v2rayquic/client.go +++ b/transport/v2rayquic/client.go @@ -72,8 +72,7 @@ func (c *Client) offerNew() (quic.Connection, error) { if err != nil { 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) if err != nil { packetConn.Close()