Skip to content

Commit 442581d

Browse files
authored
Fixing all the lint errors (#3288)
* Fixing all the lint errors! * update lint settings
1 parent efec9ea commit 442581d

File tree

31 files changed

+63
-61
lines changed

31 files changed

+63
-61
lines changed

.github/linters/.golangci.yml

-3
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,12 @@ linters:
3232
- revive
3333
- rowserrcheck
3434
- staticcheck
35-
- structcheck
3635
- stylecheck
3736
- typecheck
3837
- unconvert
3938
- unparam
40-
- varcheck
4139
- whitespace
4240
disable:
43-
- deadcode
4441
- errcheck
4542
- unused
4643

app/commander/commander.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ package commander
44

55
import (
66
"context"
7-
"github.com/v2fly/v2ray-core/v5/features"
87
"net"
98
"sync"
109

@@ -14,6 +13,7 @@ import (
1413
"github.com/v2fly/v2ray-core/v5/common"
1514
"github.com/v2fly/v2ray-core/v5/common/serial"
1615
"github.com/v2fly/v2ray-core/v5/common/signal/done"
16+
"github.com/v2fly/v2ray-core/v5/features"
1717
"github.com/v2fly/v2ray-core/v5/features/outbound"
1818
"github.com/v2fly/v2ray-core/v5/infra/conf/v5cfg"
1919
)

app/commander/webcommander/webcommander.go

+3-6
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ func newWebCommander(ctx context.Context, config *Config) (*WebCommander, error)
3838
}
3939

4040
return &WebCommander{ctx: ctx, config: config, webRootfs: webRootfs}, nil
41-
4241
}
4342

4443
type WebCommander struct {
@@ -56,9 +55,9 @@ type WebCommander struct {
5655
}
5756

5857
func (w *WebCommander) ServeHTTP(writer http.ResponseWriter, request *http.Request) {
59-
api_path := w.config.ApiMountpoint
60-
if strings.HasPrefix(request.URL.Path, api_path) {
61-
request.URL.Path = strings.TrimPrefix(request.URL.Path, api_path)
58+
apiPath := w.config.ApiMountpoint
59+
if strings.HasPrefix(request.URL.Path, apiPath) {
60+
request.URL.Path = strings.TrimPrefix(request.URL.Path, apiPath)
6261
if w.wrappedGrpc.IsGrpcWebRequest(request) {
6362
w.wrappedGrpc.ServeHTTP(writer, request)
6463
return
@@ -109,7 +108,6 @@ func (w *WebCommander) Type() interface{} {
109108
}
110109

111110
func (w *WebCommander) Start() error {
112-
113111
if err := core.RequireFeatures(w.ctx, func(cm commander.CommanderIfce, om outbound.Manager) {
114112
w.Lock()
115113
defer w.Unlock()
@@ -118,7 +116,6 @@ func (w *WebCommander) Start() error {
118116
w.ohm = om
119117

120118
go w.asyncStart()
121-
122119
}); err != nil {
123120
return err
124121
}

app/dns/dnscommon_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func Test_parseResponse(t *testing.T) {
8989
got.Expire = time.Time{}
9090
}
9191
if cmp.Diff(got, tt.want) != "" {
92-
t.Errorf(cmp.Diff(got, tt.want))
92+
t.Errorf("%v", cmp.Diff(got, tt.want))
9393
// t.Errorf("handleResponse() = %#v, want %#v", got, tt.want)
9494
}
9595
})

app/router/command/command_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ func TestServiceSubscribeRoutingStats(t *testing.T) {
9797
grpc.WithContextDialer(bufDialer),
9898
grpc.WithTransportCredentials(insecure.NewCredentials()),
9999
)
100-
101100
if err != nil {
102101
errCh <- err
103102
return

app/subscription/containers/urlline/parser.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ package urlline
33
import (
44
"bufio"
55
"bytes"
6-
"github.com/v2fly/v2ray-core/v5/app/subscription/containers"
7-
"github.com/v2fly/v2ray-core/v5/common"
86
"net/url"
97
"strings"
8+
9+
"github.com/v2fly/v2ray-core/v5/app/subscription/containers"
10+
"github.com/v2fly/v2ray-core/v5/common"
1011
)
1112

1213
func newURLLineParser() containers.SubscriptionContainerDocumentParser {

app/subscription/subscriptionmanager/tracked_subscription.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ type materializedServer struct {
7777
serverConfig *specs.SubscriptionServerConfig
7878
}
7979

80-
func (s *trackedSubscription) fillStatus(status *subscription.TrackedSubscriptionStatus) error {
80+
func (s *trackedSubscription) fillStatus(status *subscription.TrackedSubscriptionStatus) error { //nolint: unparam
8181
status.ImportSource = s.importSource
8282
if s.currentDocument == nil {
8383
return nil

common/net/packetaddr/packetaddr.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ package packetaddr
22

33
import (
44
"bytes"
5-
"github.com/v2fly/v2ray-core/v5/common/errors"
65
gonet "net"
76

87
"github.com/v2fly/v2ray-core/v5/common/buf"
8+
"github.com/v2fly/v2ray-core/v5/common/errors"
99
"github.com/v2fly/v2ray-core/v5/common/net"
1010
"github.com/v2fly/v2ray-core/v5/common/protocol"
1111
)

common/platform/platform_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func TestWrongErrorCheckOnOSStat(t *testing.T) {
5757
// be discovered by the Go runtime, which will lead to failure to
5858
// find & read geoip & geosite files.
5959
// The correct code is `errors.Is(err, fs.ErrNotExist)`
60-
if _, err := os.Stat(p); err != nil && errors.Is(fs.ErrNotExist, err) {
60+
if _, err := os.Stat(p); err != nil && errors.Is(fs.ErrNotExist, err) { //nolint: staticcheck
6161
continue
6262
}
6363
// asset found

infra/conf/v4/transport_internet.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -147,19 +147,20 @@ type Hy2ConfigCongestion struct {
147147
type Hy2Config struct {
148148
Password string `json:"password"`
149149
Congestion Hy2ConfigCongestion `json:"congestion"`
150-
UseUdpExtension bool `json:"use_udp_extension"`
150+
UseUDPExtension bool `json:"use_udp_extension"`
151151
IgnoreClientBandwidth bool `json:"ignore_client_bandwidth"`
152152
}
153153

154154
// Build implements Buildable.
155155
func (c *Hy2Config) Build() (proto.Message, error) {
156-
return &hysteria2.Config{Password: c.Password,
156+
return &hysteria2.Config{
157+
Password: c.Password,
157158
Congestion: &hysteria2.Congestion{
158159
Type: c.Congestion.Type,
159160
DownMbps: c.Congestion.DownMbps,
160161
UpMbps: c.Congestion.UpMbps,
161162
},
162-
UseUdpExtension: c.UseUdpExtension,
163+
UseUdpExtension: c.UseUDPExtension,
163164
IgnoreClientBandwidth: c.IgnoreClientBandwidth,
164165
}, nil
165166
}

infra/vprotogen/main.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ Command "%s" not found.
9393
Make sure that %s is in your system path or current path.
9494
Download %s v%s or later from https://github.com/protocolbuffers/protobuf/releases
9595
`, protoc, protoc, protoc, targetedVersion)
96-
return "", fmt.Errorf(errStr)
96+
return "", fmt.Errorf("%v", errStr)
9797
}
9898
return path, nil
9999
}
@@ -124,7 +124,7 @@ func getInstalledProtocVersion(protocPath string) (string, error) {
124124
matched := versionRegexp.FindStringSubmatch(string(output))
125125
installedVersion := ""
126126
if len(matched) == 0 {
127-
return "", errors.New("Can not parse protoc version.")
127+
return "", errors.New("can not parse protoc version")
128128
}
129129

130130
if len(matched) == 2 {

main/commands/all/jsonv4/convert.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func executeConvert(cmd *base.Command, args []string) {
119119
r := bytes.NewReader(data)
120120
pbConfig, err := core.LoadConfig(inputFormat, r)
121121
if err != nil {
122-
base.Fatalf(err.Error())
122+
base.Fatalf("%v", err.Error())
123123
}
124124
out, err = proto.Marshal(pbConfig)
125125
if err != nil {
@@ -133,12 +133,12 @@ func executeConvert(cmd *base.Command, args []string) {
133133
r := bytes.NewReader(data)
134134
pbConfig, err := core.LoadConfig(inputFormat, r)
135135
if err != nil {
136-
base.Fatalf(err.Error())
136+
base.Fatalf("%v", err.Error())
137137
}
138138
w := bytes.NewBuffer(nil)
139139
err = jsonpb.DumpJSONPb(pbConfig, w)
140140
if err != nil {
141-
base.Fatalf(err.Error())
141+
base.Fatalf("%v", err.Error())
142142
}
143143
out = w.Bytes()
144144
case v2jsonpb.FormatProtobufV2JSONPB:
@@ -149,11 +149,11 @@ func executeConvert(cmd *base.Command, args []string) {
149149
r := bytes.NewReader(data)
150150
pbConfig, err := core.LoadConfig(inputFormat, r)
151151
if err != nil {
152-
base.Fatalf(err.Error())
152+
base.Fatalf("%v", err.Error())
153153
}
154154
out, err = v2jsonpb.DumpV2JsonPb(pbConfig)
155155
if err != nil {
156-
base.Fatalf(err.Error())
156+
base.Fatalf("%v", err.Error())
157157
}
158158
default:
159159
base.Errorf("invalid output format: %s", outputFormat)

main/commands/run.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ func readConfDirRecursively(dirPath string, extension []string) cmdarg.Arg {
166166
func getConfigFilePath() cmdarg.Arg {
167167
extension, err := core.GetLoaderExtensions(*configFormat)
168168
if err != nil {
169-
base.Fatalf(err.Error())
169+
base.Fatalf("%v", err.Error())
170170
}
171171
dirReader := readConfDir
172172
if *configDirRecursively {

main/plugins/plugin_pprof/plugin_pprof.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
package plugin_pprof
1+
package plugin_pprof //nolint: stylecheck
22

33
import (
4-
"github.com/v2fly/v2ray-core/v5/main/plugins"
54
"net/http"
65
"net/http/pprof"
76

87
"github.com/v2fly/v2ray-core/v5/main/commands/base"
8+
"github.com/v2fly/v2ray-core/v5/main/plugins"
99
)
1010

1111
var pprofPlugin plugins.Plugin = func(cmd *base.Command) func() error {

proxy/hysteria2/client.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func (c *Client) Process(ctx context.Context, link *transport.Link, dialer inter
8888

8989
if !IsHy2Transport && network == net.Network_UDP {
9090
// hysteria2 need to use udp extension to proxy UDP.
91-
return newError(hyTransport.CanNotUseUdpExtension)
91+
return newError(hyTransport.CanNotUseUDPExtension)
9292
}
9393

9494
user := server.PickUser()

proxy/hysteria2/protocol.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import (
44
"io"
55
"math/rand"
66

7-
hyProtocol "github.com/v2fly/hysteria/core/v2/international/protocol"
87
"github.com/apernet/quic-go/quicvarint"
8+
hyProtocol "github.com/v2fly/hysteria/core/v2/international/protocol"
99

1010
"github.com/v2fly/v2ray-core/v5/common/buf"
1111
"github.com/v2fly/v2ray-core/v5/common/net"
@@ -59,7 +59,7 @@ func (c *ConnWriter) WriteTCPHeader() error {
5959
}
6060

6161
func QuicLen(s int) int {
62-
return int(quicvarint.Len(uint64(s)))
62+
return quicvarint.Len(uint64(s))
6363
}
6464

6565
func (c *ConnWriter) writeTCPHeader() error {

proxy/hysteria2/server.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func (s *Server) Process(ctx context.Context, network net.Network, conn internet
6767
}
6868

6969
if !IsHy2Transport && network == net.Network_UDP {
70-
return newError(hyTransport.CanNotUseUdpExtension)
70+
return newError(hyTransport.CanNotUseUDPExtension)
7171
}
7272

7373
sessionPolicy := s.policyManager.ForLevel(0)

proxy/vlite/inbound/inbound.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ func createStatusFromConfig(config *UDPProtocolConfig) (*status, error) { //noli
146146
return s, nil
147147
}
148148

149-
func enableInterface(s *status) error {
149+
func enableInterface(s *status) error { //nolint: unparam
150150
s.transport = s
151151
if s.config.EnableStabilization {
152152
s.transport = uniserver.NewUnifiedConnectionTransportHub(s, s.ctx)

testing/scenarios/common.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"bytes"
55
"crypto/rand"
66
"fmt"
7-
"golang.org/x/net/proxy"
87
"io"
98
"os"
109
"os/exec"
@@ -14,6 +13,8 @@ import (
1413
"syscall"
1514
"time"
1615

16+
"golang.org/x/net/proxy"
17+
1718
"google.golang.org/protobuf/proto"
1819

1920
core "github.com/v2fly/v2ray-core/v5"
@@ -169,7 +170,7 @@ func withDefaultApps(config *core.Config) *core.Config {
169170
return config
170171
}
171172

172-
func testTCPConnViaSocks(socksPort, testPort net.Port, payloadSize int, timeout time.Duration) func() error {
173+
func testTCPConnViaSocks(socksPort, testPort net.Port, payloadSize int, timeout time.Duration) func() error { //nolint: unparam
173174
return func() error {
174175
socksDialer, err := proxy.SOCKS5("tcp", "127.0.0.1:"+socksPort.String(), nil, nil)
175176
if err != nil {

transport/internet/httpupgrade/connection.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ package httpupgrade
22

33
import (
44
"context"
5+
"io"
6+
"time"
7+
58
"github.com/v2fly/v2ray-core/v5/common/buf"
69
"github.com/v2fly/v2ray-core/v5/common/net"
710
"github.com/v2fly/v2ray-core/v5/common/serial"
8-
"io"
9-
"time"
1011
)
1112

1213
type connection struct {

transport/internet/httpupgrade/dialer.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ func dialhttpUpgrade(ctx context.Context, dest net.Destination, streamSettings *
4343
earlyDataSize = int(transportConfiguration.MaxEarlyData)
4444
}
4545

46-
if earlyData != nil && len(earlyData) > 0 {
46+
if len(earlyData) > 0 {
4747
if transportConfiguration.EarlyDataHeaderName == "" {
4848
return nil, nil, newError("EarlyDataHeaderName is not set")
4949
}
@@ -71,7 +71,6 @@ func dialhttpUpgrade(ctx context.Context, dest net.Destination, streamSettings *
7171
if resp.Status == "101 Switching Protocols" &&
7272
strings.ToLower(resp.Header.Get("Upgrade")) == "websocket" &&
7373
strings.ToLower(resp.Header.Get("Connection")) == "upgrade" {
74-
7574
earlyReplyReader := io.LimitReader(bufferedConn, int64(bufferedConn.Buffered()))
7675
return conn, earlyReplyReader, nil
7776
}

transport/internet/hysteria2/conn.go

+8-6
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,18 @@ package hysteria2
33
import (
44
"time"
55

6+
"github.com/apernet/quic-go"
67
hyClient "github.com/v2fly/hysteria/core/v2/client"
78
"github.com/v2fly/hysteria/core/v2/international/protocol"
89
hyServer "github.com/v2fly/hysteria/core/v2/server"
9-
"github.com/apernet/quic-go"
1010

1111
"github.com/v2fly/v2ray-core/v5/common/net"
1212
)
1313

14-
const CanNotUseUdpExtension = "Only hysteria2 proxy protocol can use udpExtension."
15-
const Hy2MustNeedTLS = "Hysteria2 based on QUIC that requires TLS."
14+
const (
15+
CanNotUseUDPExtension = "Only hysteria2 proxy protocol can use udpExtension."
16+
Hy2MustNeedTLS = "Hysteria2 based on QUIC that requires TLS."
17+
)
1618

1719
type HyConn struct {
1820
IsUDPExtension bool
@@ -44,7 +46,7 @@ func (c *HyConn) Write(b []byte) (int, error) {
4446

4547
func (c *HyConn) WritePacket(b []byte, dest net.Destination) (int, error) {
4648
if !c.IsUDPExtension {
47-
return 0, newError(CanNotUseUdpExtension)
49+
return 0, newError(CanNotUseUDPExtension)
4850
}
4951

5052
if c.IsServer {
@@ -64,7 +66,7 @@ func (c *HyConn) WritePacket(b []byte, dest net.Destination) (int, error) {
6466

6567
func (c *HyConn) ReadPacket() (int, []byte, *net.Destination, error) {
6668
if !c.IsUDPExtension {
67-
return 0, nil, nil, newError(CanNotUseUdpExtension)
69+
return 0, nil, nil, newError(CanNotUseUDPExtension)
6870
}
6971

7072
if c.IsServer {
@@ -89,7 +91,7 @@ func (c *HyConn) ReadPacket() (int, []byte, *net.Destination, error) {
8991
func (c *HyConn) Close() error {
9092
if c.IsUDPExtension {
9193
if !c.IsServer && c.ClientUDPSession == nil || (c.IsServer && c.ServerUDPSession == nil) {
92-
return newError(CanNotUseUdpExtension)
94+
return newError(CanNotUseUDPExtension)
9395
}
9496
if c.IsServer {
9597
c.ServerUDPSession.CloseWithErr(nil)

0 commit comments

Comments
 (0)