* update golangci-lint to 1.46.2

Signed-off-by: Andres Taylor <andres@planetscale.com>

* ci: update golangci-lint

Signed-off-by: Andres Taylor <andres@planetscale.com>

* address all new linter warnings

Signed-off-by: Andres Taylor <andres@planetscale.com>
This commit is contained in:
Andres Taylor 2022-06-23 13:04:28 +02:00 коммит произвёл GitHub
Родитель cc7974f974
Коммит 08dfc4eb7e
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
20 изменённых файлов: 36 добавлений и 32 удалений

2
.github/workflows/static_checks_etc.yml поставляемый
Просмотреть файл

@ -137,7 +137,7 @@ jobs:
- name: Install golangci-lint
if: steps.changes.outputs.go_files == 'true'
run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.45.2
run: go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.46.2
- name: Clean Env
if: steps.changes.outputs.go_files == 'true'

Просмотреть файл

@ -159,4 +159,4 @@ issues:
# https://github.com/golangci/golangci/wiki/Configuration
service:
golangci-lint-version: 1.45.0 # use the fixed version to not introduce new linters unexpectedly
golangci-lint-version: 1.46.2 # use the fixed version to not introduce new linters unexpectedly

Просмотреть файл

@ -655,9 +655,7 @@ type testConn struct {
}
func (t testConn) Read(b []byte) (n int, err error) {
for j, i := range t.queryPacket {
b[j] = i
}
copy(b, t.queryPacket)
return len(b), nil
}

Просмотреть файл

@ -258,8 +258,5 @@ func (vtctlclient *VtctlClientProcess) InitTablet(tablet *Vttablet, cell string,
// shouldRetry tells us if the command should be retried based on the results/output -- meaning that it
// is likely an ephemeral or recoverable issue that is likely to succeed when retried.
func shouldRetry(cmdResults string) bool {
if strings.Contains(cmdResults, "Deadlock found when trying to get lock; try restarting transaction") {
return true
}
return false
return strings.Contains(cmdResults, "Deadlock found when trying to get lock; try restarting transaction")
}

Просмотреть файл

@ -68,7 +68,7 @@ func NewMySQL(cluster *cluster.LocalProcessCluster, dbName string, schemaSQL ...
}
for _, sql := range schemaSQL {
err = prepareMySQLWithSchema(err, params, sql)
err = prepareMySQLWithSchema(params, sql)
if err != nil {
return mysql.ConnParams{}, nil, err
}
@ -119,7 +119,7 @@ func initMysqld(mysqld *mysqlctl.Mysqld, mycnf *mysqlctl.Mycnf, initSQLFile stri
return nil
}
func prepareMySQLWithSchema(err error, params mysql.ConnParams, sql string) error {
func prepareMySQLWithSchema(params mysql.ConnParams, sql string) error {
ctx := context.Background()
conn, err := mysql.Connect(ctx, &params)
if err != nil {

Просмотреть файл

@ -802,7 +802,7 @@ func SetupNewClusterSemiSync(t *testing.T) *VtOrcClusterInfo {
vtctldClientProcess := cluster.VtctldClientProcessInstance("localhost", clusterInstance.VtctldProcess.GrpcPort, clusterInstance.TmpDirectory)
out, err := vtctldClientProcess.ExecuteCommandWithOutput("SetKeyspaceDurabilityPolicy", keyspaceName, fmt.Sprintf("--durability-policy=semi_sync"))
out, err := vtctldClientProcess.ExecuteCommandWithOutput("SetKeyspaceDurabilityPolicy", keyspaceName, "--durability-policy=semi_sync")
require.NoError(t, err, out)
clusterInfo := &VtOrcClusterInfo{
@ -877,7 +877,7 @@ func AddSemiSyncKeyspace(t *testing.T, clusterInfo *VtOrcClusterInfo) {
}
vtctldClientProcess := cluster.VtctldClientProcessInstance("localhost", clusterInfo.ClusterInstance.VtctldProcess.GrpcPort, clusterInfo.ClusterInstance.TmpDirectory)
out, err := vtctldClientProcess.ExecuteCommandWithOutput("SetKeyspaceDurabilityPolicy", keyspaceSemiSyncName, fmt.Sprintf("--durability-policy=semi_sync"))
out, err := vtctldClientProcess.ExecuteCommandWithOutput("SetKeyspaceDurabilityPolicy", keyspaceSemiSyncName, "--durability-policy=semi_sync")
require.NoError(t, err, out)
}

Просмотреть файл

@ -495,7 +495,7 @@ func main() {
flag.Parse()
// The -version flag must be of a valid format.
rx := regexp.MustCompile("v([0-9]+)\\.([0-9]+)\\.([0-9]+)")
rx := regexp.MustCompile(`v(\d+)\.(\d+)\.(\d+)`)
// There should be 4 sub-matches, input: "v14.0.0", output: ["v14.0.0", "14", "0", "0"].
versionMatch := rx.FindStringSubmatch(*versionName)
if len(versionMatch) != 4 {

Просмотреть файл

@ -24,6 +24,8 @@ import (
"flag"
"time"
"google.golang.org/grpc/credentials/insecure"
grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
grpc_prometheus "github.com/grpc-ecosystem/go-grpc-prometheus"
"google.golang.org/grpc"
@ -128,7 +130,7 @@ func interceptors() []grpc.DialOption {
func SecureDialOption(cert, key, ca, crl, name string) (grpc.DialOption, error) {
// No security options set, just return.
if (cert == "" || key == "") && ca == "" {
return grpc.WithInsecure(), nil
return grpc.WithTransportCredentials(insecure.NewCredentials()), nil
}
// Load the config. At this point we know

Просмотреть файл

@ -22,6 +22,8 @@ import (
"testing"
"time"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc"
vtgatepb "vitess.io/vitess/go/vt/proto/vtgate"
@ -36,7 +38,7 @@ func TestDialErrors(t *testing.T) {
}
wantErr := "Unavailable"
for _, address := range addresses {
gconn, err := Dial(address, FailFast(true), grpc.WithInsecure())
gconn, err := Dial(address, true, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatal(err)
}
@ -52,7 +54,7 @@ func TestDialErrors(t *testing.T) {
wantErr = "DeadlineExceeded"
for _, address := range addresses {
gconn, err := Dial(address, FailFast(false), grpc.WithInsecure())
gconn, err := Dial(address, false, grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatal(err)
}

Просмотреть файл

@ -19,6 +19,8 @@ import (
"testing"
"time"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
pb "google.golang.org/grpc/examples/helloworld/helloworld"
@ -110,7 +112,7 @@ func TestOptionalTLS(t *testing.T) {
t.Run("Plain2TLS", func(t *testing.T) {
for i := 0; i < 5; i++ {
testFunc(t, grpc.WithInsecure())
testFunc(t, grpc.WithTransportCredentials(insecure.NewCredentials()))
}
})
t.Run("TLS2TLS", func(t *testing.T) {

Просмотреть файл

@ -22,6 +22,8 @@ import (
"testing"
"time"
"google.golang.org/grpc/credentials/insecure"
"github.com/stretchr/testify/assert"
"golang.org/x/net/nettest"
"google.golang.org/grpc"
@ -62,7 +64,7 @@ func TestServer(t *testing.T) {
}
close(readyCh)
conn, err := grpc.Dial(lis.Addr().String(), grpc.WithInsecure(), grpc.WithBlock())
conn, err := grpc.Dial(lis.Addr().String(), grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithBlock())
assert.NoError(t, err)
defer conn.Close()

Просмотреть файл

@ -21,6 +21,8 @@ import (
"sync"
"time"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc"
grpcresolver "google.golang.org/grpc/resolver"
@ -113,7 +115,7 @@ func (vtctld *ClientProxy) dial(ctx context.Context) error {
// TODO: make configurable. right now, omitting this and attempting
// to not use TLS results in:
// grpc: no transport security set (use grpc.WithInsecure() explicitly or set credentials)
grpc.WithInsecure(),
grpc.WithTransportCredentials(insecure.NewCredentials()),
}
if vtctld.creds != nil {

Просмотреть файл

@ -23,6 +23,8 @@ import (
"sync"
"time"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc"
grpcresolver "google.golang.org/grpc/resolver"
@ -137,7 +139,7 @@ func (vtgate *VTGateProxy) dial(ctx context.Context, target string, opts ...grpc
Protocol: fmt.Sprintf("grpc_%s", vtgate.cluster.Id),
Address: resolver.DialAddr(vtgate.resolver, "vtgate"),
Target: target,
GRPCDialOptions: append(opts, grpc.WithInsecure(), grpc.WithResolvers(vtgate.resolver)),
GRPCDialOptions: append(opts, grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithResolvers(vtgate.resolver)),
}
if vtgate.creds != nil {

Просмотреть файл

@ -186,7 +186,7 @@ func (l *Lock) description() PrimitiveDescription {
}
var lf []string
for _, f := range l.LockFunctions {
lf = append(lf, fmt.Sprintf("%s", sqlparser.String(f.Typ)))
lf = append(lf, sqlparser.String(f.Typ))
}
other["lock_func"] = lf
return PrimitiveDescription{

Просмотреть файл

@ -351,7 +351,7 @@ func TestNumericTypes(t *testing.T) {
defer conn.Close()
for _, rhs := range numbers {
compareRemoteExpr(t, conn, fmt.Sprintf("%s", rhs))
compareRemoteExpr(t, conn, rhs)
}
}
@ -527,7 +527,7 @@ func TestLargeIntegers(t *testing.T) {
var largepi = Pi + Pi
for pos := 1; pos < len(largepi); pos++ {
query := fmt.Sprintf("%s", largepi[:pos])
query := largepi[:pos]
compareRemoteExpr(t, conn, query)
query = fmt.Sprintf("-%s", largepi[:pos])

Просмотреть файл

@ -664,9 +664,7 @@ var testPlannedQueries = map[string]bool{}
func testQueryLog(t *testing.T, logChan chan any, method, stmtType, sql string, shardQueries int) *LogStats {
t.Helper()
var logStats *LogStats
logStats = getQueryLog(logChan)
logStats := getQueryLog(logChan)
require.NotNil(t, logStats)
var log bytes.Buffer

Просмотреть файл

@ -96,9 +96,8 @@ func TestOperator(t *testing.T) {
}
t.Run(fmt.Sprintf("%d:%s", tc.line, tc.query), func(t *testing.T) {
require.NoError(t, err)
tree, err := sqlparser.Parse(tc.query)
stmt, err := sqlparser.Parse(tc.query)
require.NoError(t, err)
stmt := tree.(sqlparser.Statement)
semTable, err := semantics.Analyze(stmt, "", si)
require.NoError(t, err)
optree, err := CreateLogicalOperatorFromAST(stmt, semTable)

Просмотреть файл

@ -605,7 +605,7 @@ func TestMultiInternalSavepointVtGate(t *testing.T) {
sbc3.Queries = nil
// single shard so no savepoint will be created and neither any old savepoint will be executed
session, _, err = rpcVTGate.Execute(context.Background(), session, "insert into sp_tbl(user_id) values (5)", nil)
_, _, err = rpcVTGate.Execute(context.Background(), session, "insert into sp_tbl(user_id) values (5)", nil)
require.NoError(t, err)
wantQ = []*querypb.BoundQuery{{
Sql: "insert into sp_tbl(user_id) values (:_user_id_0)",

Просмотреть файл

@ -77,8 +77,8 @@ func TestRecalculatePKColsInfoByColumnNames(t *testing.T) {
func TestPrimaryKeyEquivalentColumns(t *testing.T) {
ctx := context.Background()
testEnv, err := testenv.Init()
defer testEnv.Close()
require.NoError(t, err)
defer testEnv.Close()
tests := []struct {
name string
table string

Просмотреть файл

@ -16,7 +16,7 @@
GOLANGCI_LINT=$(command -v golangci-lint >/dev/null 2>&1)
if [ $? -eq 1 ]; then
echo "Downloading golangci-lint..."
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.45.2
go install github.com/golangci/golangci-lint/cmd/golangci-lint@v1.46.2
fi
gofiles=$(git diff --cached --name-only --diff-filter=ACM | grep '^go/.*\.go$')