Browse Source

Lint: update linter config & fix code style (#1089)

* Lint: update linter config
* Fix: code style
Loyalsoldier 4 years ago
parent
commit
d7a202a705

+ 6 - 0
.github/linters/.golangci.yml

@@ -12,10 +12,12 @@ issues:
 
 linters:
   enable:
+    - asciicheck
     - bodyclose
     - depguard
     - gocritic
     - gofmt
+    - gofumpt
     - goimports
     - golint
     - goprintffuncname
@@ -37,3 +39,7 @@ linters:
     - deadcode
     - errcheck
     - unused
+
+linters-settings:
+  goimports:
+    local-prefixes: github.com/v2fly/v2ray-core

+ 1 - 0
.github/workflows/linter.yml

@@ -16,6 +16,7 @@ on:
 
 jobs:
   lint:
+    if: github.repository == 'v2fly/v2ray-core'
     runs-on: ubuntu-latest
     steps:
       - name: Set up Go 1.x

+ 1 - 1
app/reverse/portal.go

@@ -154,7 +154,7 @@ func (p *StaticMuxPicker) PickAvailable() (*mux.ClientWorker, error) {
 		return nil, newError("empty worker list")
 	}
 
-	var minIdx = -1
+	minIdx := -1
 	var minConn uint32 = 9999
 	for i, w := range p.workers {
 		if w.draining {

+ 1 - 1
features/routing/dns/context.go

@@ -26,7 +26,7 @@ func (ctx *ResolvableContext) GetTargetIPs() []net.IP {
 	}
 
 	if domain := ctx.GetTargetDomain(); len(domain) != 0 {
-		var lookupFunc = ctx.dnsClient.LookupIP
+		lookupFunc := ctx.dnsClient.LookupIP
 		ipOption := &dns.IPOption{
 			IPv4Enable: true,
 			IPv6Enable: true,

+ 1 - 1
proxy/freedom/freedom.go

@@ -66,7 +66,7 @@ func (h *Handler) resolveIP(ctx context.Context, domain string, localAddr net.Ad
 		newError("DNS client doesn't implement ClientWithIPOption")
 	}
 
-	var lookupFunc = h.dns.LookupIP
+	lookupFunc := h.dns.LookupIP
 	if h.config.DomainStrategy == Config_USE_IP4 || (localAddr != nil && localAddr.Family().IsIPv4()) {
 		if lookupIPv4, ok := h.dns.(dns.IPv4Lookup); ok {
 			lookupFunc = lookupIPv4.LookupIPv4

+ 0 - 2
proxy/shadowsocks/protocol.go

@@ -39,7 +39,6 @@ func ReadTCPSession(user *protocol.MemoryUser, reader io.Reader) (*protocol.Requ
 	behaviorSeed := crc32.ChecksumIEEE(hashkdf.Sum(nil))
 
 	drainer, err := drain.NewBehaviorSeedLimitedDrainer(int64(behaviorSeed), 16+38, 3266, 64)
-
 	if err != nil {
 		return nil, nil, newError("failed to initialize drainer").Base(err)
 	}
@@ -140,7 +139,6 @@ func ReadTCPResponse(user *protocol.MemoryUser, reader io.Reader) (buf.Reader, e
 	behaviorSeed := crc32.ChecksumIEEE(hashkdf.Sum(nil))
 
 	drainer, err := drain.NewBehaviorSeedLimitedDrainer(int64(behaviorSeed), 16+38, 3266, 64)
-
 	if err != nil {
 		return nil, newError("failed to initialize drainer").Base(err)
 	}

+ 1 - 2
proxy/vmess/encoding/auth.go

@@ -5,11 +5,10 @@ import (
 	"encoding/binary"
 	"hash/fnv"
 
-	"github.com/v2fly/v2ray-core/v4/common/crypto"
-
 	"golang.org/x/crypto/sha3"
 
 	"github.com/v2fly/v2ray-core/v4/common"
+	"github.com/v2fly/v2ray-core/v4/common/crypto"
 )
 
 // Authenticate authenticates a byte array using Fnv hash.

+ 1 - 2
proxy/vmess/encoding/client.go

@@ -13,8 +13,6 @@ import (
 	"hash/fnv"
 	"io"
 
-	"github.com/v2fly/v2ray-core/v4/common/drain"
-
 	"golang.org/x/crypto/chacha20poly1305"
 
 	"github.com/v2fly/v2ray-core/v4/common"
@@ -22,6 +20,7 @@ import (
 	"github.com/v2fly/v2ray-core/v4/common/buf"
 	"github.com/v2fly/v2ray-core/v4/common/crypto"
 	"github.com/v2fly/v2ray-core/v4/common/dice"
+	"github.com/v2fly/v2ray-core/v4/common/drain"
 	"github.com/v2fly/v2ray-core/v4/common/protocol"
 	"github.com/v2fly/v2ray-core/v4/common/serial"
 	"github.com/v2fly/v2ray-core/v4/proxy/vmess"

+ 1 - 3
proxy/vmess/encoding/server.go

@@ -12,14 +12,13 @@ import (
 	"sync"
 	"time"
 
-	"github.com/v2fly/v2ray-core/v4/common/drain"
-
 	"golang.org/x/crypto/chacha20poly1305"
 
 	"github.com/v2fly/v2ray-core/v4/common"
 	"github.com/v2fly/v2ray-core/v4/common/bitmask"
 	"github.com/v2fly/v2ray-core/v4/common/buf"
 	"github.com/v2fly/v2ray-core/v4/common/crypto"
+	"github.com/v2fly/v2ray-core/v4/common/drain"
 	"github.com/v2fly/v2ray-core/v4/common/net"
 	"github.com/v2fly/v2ray-core/v4/common/protocol"
 	"github.com/v2fly/v2ray-core/v4/common/task"
@@ -141,7 +140,6 @@ func (s *ServerSession) DecodeRequestHeader(reader io.Reader) (*protocol.Request
 	buffer := buf.New()
 
 	drainer, err := drain.NewBehaviorSeedLimitedDrainer(int64(s.userValidator.GetBehaviorSeed()), 16+38, 3266, 64)
-
 	if err != nil {
 		return nil, newError("failed to initialize drainer").Base(err)
 	}

+ 1 - 2
transport/internet/grpc/dial.go

@@ -8,13 +8,12 @@ import (
 	"sync"
 	"time"
 
-	core "github.com/v2fly/v2ray-core/v4"
-
 	"google.golang.org/grpc"
 	"google.golang.org/grpc/backoff"
 	"google.golang.org/grpc/connectivity"
 	"google.golang.org/grpc/credentials"
 
+	core "github.com/v2fly/v2ray-core/v4"
 	"github.com/v2fly/v2ray-core/v4/common"
 	"github.com/v2fly/v2ray-core/v4/common/net"
 	"github.com/v2fly/v2ray-core/v4/common/session"

+ 1 - 2
transport/internet/http/dialer.go

@@ -9,10 +9,9 @@ import (
 	"net/url"
 	"sync"
 
-	core "github.com/v2fly/v2ray-core/v4"
-
 	"golang.org/x/net/http2"
 
+	core "github.com/v2fly/v2ray-core/v4"
 	"github.com/v2fly/v2ray-core/v4/common"
 	"github.com/v2fly/v2ray-core/v4/common/buf"
 	"github.com/v2fly/v2ray-core/v4/common/net"