Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

linter: enable SA4018 and SA4004 #44276

Merged
merged 15 commits into from
May 31, 2023
2 changes: 2 additions & 0 deletions build/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ STATICHECK_ANALYZERS = [
"SA2003",
"SA3000",
"SA3001",
"SA4004",
"SA4009",
"SA4018",
"SA5000",
"SA5001",
"SA5002",
Expand Down
15 changes: 15 additions & 0 deletions build/nogo_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -1023,13 +1023,28 @@
".*_generated\\.go$": "ignore generated code"
}
},
"SA4004": {
"exclude_files": {
"parser/parser.go": "parser/parser.go code",
"server/http_status.go": "ignore server/http_status.go",
"external/": "no need to vet third party code",
".*_generated\\.go$": "ignore generated code"
}
},
"SA4009": {
"exclude_files": {
"parser/parser.go": "parser/parser.go code",
"external/": "no need to vet third party code",
".*_generated\\.go$": "ignore generated code"
}
},
"SA4018": {
"exclude_files": {
"parser/parser.go": "parser/parser.go code",
"external/": "no need to vet third party code",
".*_generated\\.go$": "ignore generated code"
}
},
"SA5000": {
"exclude_files": {
"parser/parser.go": "parser/parser.go code",
Expand Down
49 changes: 0 additions & 49 deletions store/mockstore/unistore/tikv/mvcc/tikv.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,52 +129,3 @@ const (
)

var errInvalidLockCFValue = errors.New("invalid lock CF value")

// ParseLockCFValue parses the []byte data and returns a MvccLock.
func ParseLockCFValue(data []byte) (lock Lock, err error) {
if len(data) == 0 {
err = errInvalidLockCFValue
return
}
switch data[0] {
case LockTypePut:
lock.Op = byte(kvrpcpb.Op_Put)
case LockTypeDelete:
lock.Op = byte(kvrpcpb.Op_Del)
case LockTypeLock:
lock.Op = byte(kvrpcpb.Op_Lock)
case LockTypePessimistic:
lock.Op = byte(kvrpcpb.Op_PessimisticLock)
default:
err = errInvalidLockCFValue
return
}
data, lock.Primary, err = codec.DecodeCompactBytes(data[1:])
if err != nil {
return
}
lock.PrimaryLen = uint16(len(lock.Primary))
data, lock.StartTS, err = codec.DecodeUvarint(data)
if err != nil || len(data) == 0 {
return
}
var ttl uint64
data, ttl, err = codec.DecodeUvarint(data)
lock.TTL = uint32(ttl)
if err != nil || len(data) == 0 {
return
}
if data[0] == shortValuePrefix {
shortValLen := int(data[1])
data = data[2:]
lock.Value = data[:shortValLen]
data = data[shortValLen:]
}
if len(data) > 0 && data[0] == forUpdatePrefix {
data, lock.ForUpdateTS, err = codec.DecodeUint(data[1:])
}
if len(data) > 0 && data[0] == minCommitTsPrefix {
data, lock.MinCommitTS, err = codec.DecodeUint(data[1:])
}
return
}
5 changes: 2 additions & 3 deletions util/dbutil/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ func GetTidbLatestTSO(ctx context.Context, db QueryExecutor) (int64, error) {
}
defer rows.Close()

for rows.Next() {
if rows.Next() {
fields, err1 := ScanRow(rows)
if err1 != nil {
return 0, errors.Trace(err1)
Expand Down Expand Up @@ -648,12 +648,11 @@ func GetDBVersion(ctx context.Context, db QueryExecutor) (string, error) {
defer result.Close()

var version sql.NullString
for result.Next() {
if result.Next() {
err := result.Scan(&version)
if err != nil {
return "", errors.Trace(err)
}
break
}

if version.Valid {
Expand Down