diff --git a/br/pkg/lightning/backend/local/local.go b/br/pkg/lightning/backend/local/local.go index 8a45472dddfcc..6679d8bf93b98 100644 --- a/br/pkg/lightning/backend/local/local.go +++ b/br/pkg/lightning/backend/local/local.go @@ -1504,7 +1504,6 @@ func (local *local) ResolveDuplicateRows(ctx context.Context, tbl table.Table, t logger.Warn("[resolve-dupe] skipping resolution due to selected algorithm. this table will become inconsistent!", zap.Stringer("algorithm", algorithm)) return nil case config.DupeResAlgRemove: - break default: panic(fmt.Sprintf("[resolve-dupe] unknown resolution algorithm %v", algorithm)) } diff --git a/br/pkg/lightning/config/config.go b/br/pkg/lightning/config/config.go index b0ffe32fa3cd5..0066895568550 100644 --- a/br/pkg/lightning/config/config.go +++ b/br/pkg/lightning/config/config.go @@ -1156,7 +1156,7 @@ func (cfg *Config) CheckAndAdjustSecurity() error { return common.ErrInvalidConfig.GenWithStack("cannot set `tidb.tls` to 'cluster' without a [security] section") } case "false", "skip-verify", "preferred": - break + return nil default: return common.ErrInvalidConfig.GenWithStack("unsupported `tidb.tls` config %s", cfg.TiDB.TLS) } diff --git a/br/pkg/lightning/restore/restore.go b/br/pkg/lightning/restore/restore.go index 6246c27ef411b..faf774efa5c7a 100644 --- a/br/pkg/lightning/restore/restore.go +++ b/br/pkg/lightning/restore/restore.go @@ -916,7 +916,6 @@ func (rc *Controller) saveStatusCheckpoint(ctx context.Context, tableName string switch { case err == nil: - break case utils.MessageIsRetryableStorageError(err.Error()), common.IsContextCanceledError(err): // recoverable error, should not be recorded in checkpoint // which will prevent lightning from automatically recovering diff --git a/build/BUILD.bazel b/build/BUILD.bazel index 6957be918b42b..b283c4b2e0f20 100644 --- a/build/BUILD.bazel +++ b/build/BUILD.bazel @@ -4,17 +4,41 @@ load("@io_bazel_rules_go//go:def.bzl", "nogo") load("//build/linter/staticcheck:def.bzl", "staticcheck_analyzers") STATICHECK_ANALYZERS = [ + "S1000", + "S1001", "S1002", + "S1003", "S1004", + "S1005", + "S1006", "S1007", + "S1008", "S1009", "S1010", + "S1011", "S1012", + "S1016", + "S1017", + "S1018", "S1019", "S1020", "S1021", + "S1023", "S1024", + "S1025", + "S1028", + "S1029", "S1030", + "S1031", + "S1032", + "S1033", + "S1034", + "S1035", + "S1036", + "S1037", + "S1038", + "S1039", + "S1040", "SA2000", "SA2001", "SA2003", diff --git a/build/nogo_config.json b/build/nogo_config.json index cefdb5fe4aa11..8f7f4e940a597 100644 --- a/build/nogo_config.json +++ b/build/nogo_config.json @@ -230,24 +230,60 @@ "parser/digester_test.go": "ignore code" } }, + "S1000": { + "exclude_files": { + "/external/": "no need to vet third party code", + ".*_generated\\.go$": "ignore generated code" + } + }, + "S1001": { + "exclude_files": { + "/external/": "no need to vet third party code", + ".*_generated\\.go$": "ignore generated code" + } + }, "S1002": { "exclude_files": { "/external/": "no need to vet third party code", ".*_generated\\.go$": "ignore generated code" } }, + "S1003": { + "exclude_files": { + "/external/": "no need to vet third party code", + ".*_generated\\.go$": "ignore generated code" + } + }, "S1004": { "exclude_files": { "/external/": "no need to vet third party code", ".*_generated\\.go$": "ignore generated code" } }, + "S1005": { + "exclude_files": { + "/external/": "no need to vet third party code", + ".*_generated\\.go$": "ignore generated code" + } + }, + "S1006": { + "exclude_files": { + "/external/": "no need to vet third party code", + ".*_generated\\.go$": "ignore generated code" + } + }, "S1007": { "exclude_files": { "/external/": "no need to vet third party code", ".*_generated\\.go$": "ignore generated code" } }, + "S1008": { + "exclude_files": { + "/external/": "no need to vet third party code", + ".*_generated\\.go$": "ignore generated code" + } + }, "S1009": { "exclude_files": { "/external/": "no need to vet third party code", @@ -260,12 +296,54 @@ ".*_generated\\.go$": "ignore generated code" } }, + "S1011": { + "exclude_files": { + "/external/": "no need to vet third party code", + ".*_generated\\.go$": "ignore generated code" + } + }, "S1012": { "exclude_files": { "/external/": "no need to vet third party code", ".*_generated\\.go$": "ignore generated code" } }, + "S1013": { + "exclude_files": { + "/external/": "no need to vet third party code", + ".*_generated\\.go$": "ignore generated code" + } + }, + "S1014": { + "exclude_files": { + "/external/": "no need to vet third party code", + ".*_generated\\.go$": "ignore generated code" + } + }, + "S1015": { + "exclude_files": { + "/external/": "no need to vet third party code", + ".*_generated\\.go$": "ignore generated code" + } + }, + "S1016": { + "exclude_files": { + "/external/": "no need to vet third party code", + ".*_generated\\.go$": "ignore generated code" + } + }, + "S1017": { + "exclude_files": { + "/external/": "no need to vet third party code", + ".*_generated\\.go$": "ignore generated code" + } + }, + "S1018": { + "exclude_files": { + "/external/": "no need to vet third party code", + ".*_generated\\.go$": "ignore generated code" + } + }, "S1019": { "exclude_files": { "/external/": "no need to vet third party code", @@ -286,18 +364,122 @@ "tools/check/ut.go": "ignore code" } }, + "S1022": { + "exclude_files": { + "/external/": "no need to vet third party code", + ".*_generated\\.go$": "ignore generated code" + } + }, + "S1023": { + "exclude_files": { + "/external/": "no need to vet third party code", + ".*_generated\\.go$": "ignore generated code", + "parser/parser.go": "ignore code" + } + }, "S1024": { "exclude_files": { "/external/": "no need to vet third party code", ".*_generated\\.go$": "ignore generated code" } }, + "S1025": { + "exclude_files": { + "/external/": "no need to vet third party code", + ".*_generated\\.go$": "ignore generated code" + } + }, + "S1026": { + "exclude_files": { + "/external/": "no need to vet third party code", + ".*_generated\\.go$": "ignore generated code" + } + }, + "S1027": { + "exclude_files": { + "/external/": "no need to vet third party code", + ".*_generated\\.go$": "ignore generated code" + } + }, + "S1028": { + "exclude_files": { + "/external/": "no need to vet third party code", + ".*_generated\\.go$": "ignore generated code" + } + }, + "S1029": { + "exclude_files": { + "/external/": "no need to vet third party code", + ".*_generated\\.go$": "ignore generated code" + } + }, "S1030": { "exclude_files": { "/external/": "no need to vet third party code", ".*_generated\\.go$": "ignore generated code" } }, + "S1031": { + "exclude_files": { + "/external/": "no need to vet third party code", + ".*_generated\\.go$": "ignore generated code" + } + }, + "S1032": { + "exclude_files": { + "/external/": "no need to vet third party code", + ".*_generated\\.go$": "ignore generated code" + } + }, + "S1033": { + "exclude_files": { + "/external/": "no need to vet third party code", + ".*_generated\\.go$": "ignore generated code" + } + }, + "S1034": { + "exclude_files": { + "/external/": "no need to vet third party code", + ".*_generated\\.go$": "ignore generated code" + } + }, + "S1035": { + "exclude_files": { + "/external/": "no need to vet third party code", + ".*_generated\\.go$": "ignore generated code" + } + }, + "S1036": { + "exclude_files": { + "/external/": "no need to vet third party code", + ".*_generated\\.go$": "ignore generated code" + } + }, + "S1037": { + "exclude_files": { + "/external/": "no need to vet third party code", + ".*_generated\\.go$": "ignore generated code" + } + }, + "S1038": { + "exclude_files": { + "/external/": "no need to vet third party code", + ".*_generated\\.go$": "ignore generated code" + } + }, + "S1039": { + "exclude_files": { + "/external/": "no need to vet third party code", + ".*_generated\\.go$": "ignore generated code" + } + }, + "S1040": { + "exclude_files": { + "/external/": "no need to vet third party code", + ".*_generated\\.go$": "ignore generated code", + "parser/parser.go": "ignore generated code" + } + }, "SA2000": { "exclude_files": { "/external/": "no need to vet third party code", diff --git a/ddl/ddl_api.go b/ddl/ddl_api.go index 23a0de2c32eb6..d0b799731a779 100644 --- a/ddl/ddl_api.go +++ b/ddl/ddl_api.go @@ -4706,7 +4706,6 @@ func checkAutoRandom(tableInfo *model.TableInfo, originCol *table.Column, specNe } switch { case oldRandBits == newRandBits: - break case oldRandBits < newRandBits: addingAutoRandom := oldRandBits == 0 if addingAutoRandom { @@ -6341,7 +6340,6 @@ func validateCommentLength(vars *variable.SessionVars, name string, comment *str case dbterror.ErrTooLongTableComment: maxLen *= 2 case dbterror.ErrTooLongFieldComment, dbterror.ErrTooLongIndexComment, dbterror.ErrTooLongTablePartitionComment: - break default: // add more types of terror.Error if need } @@ -6405,7 +6403,6 @@ func checkColumnsTypeAndValuesMatch(ctx sessionctx.Context, meta *model.TableInf case mysql.TypeDate, mysql.TypeDatetime, mysql.TypeDuration: switch vkind { case types.KindString, types.KindBytes: - break default: return dbterror.ErrWrongTypeColumnValue.GenWithStackByArgs() } diff --git a/executor/brie.go b/executor/brie.go index 3cd1ce7ea9e1e..78fdcbe9f1285 100644 --- a/executor/brie.go +++ b/executor/brie.go @@ -249,7 +249,6 @@ func (b *executorBuilder) buildBRIE(s *ast.BRIEStmt, schema *expression.Schema) return nil } default: - break } if tidbCfg.Store != "tikv" { diff --git a/executor/merge_join_test.go b/executor/merge_join_test.go index a140809fd46d2..2a46243c6e6cc 100644 --- a/executor/merge_join_test.go +++ b/executor/merge_join_test.go @@ -785,11 +785,11 @@ func TestVectorizedMergeJoin(t *testing.T) { )).Check(testkit.Rows( fmt.Sprintf(`MergeJoin 4150.01 root inner join, left key:test.%s.a, right key:test.%s.a`, t1, t2), fmt.Sprintf(`├─Sort(Build) 3320.01 root test.%s.a`, t2), - fmt.Sprintf(`│ └─TableReader 3320.01 root data:Selection`), + `│ └─TableReader 3320.01 root data:Selection`, fmt.Sprintf(`│ └─Selection 3320.01 cop[tikv] lt(test.%s.b, 5), not(isnull(test.%s.a))`, t2, t2), fmt.Sprintf(`│ └─TableFullScan 10000.00 cop[tikv] table:%s keep order:false, stats:pseudo`, t2), fmt.Sprintf(`└─Sort(Probe) 3330.00 root test.%s.a`, t1), - fmt.Sprintf(` └─TableReader 3330.00 root data:Selection`), + ` └─TableReader 3330.00 root data:Selection`, fmt.Sprintf(` └─Selection 3330.00 cop[tikv] gt(test.%s.b, 5), not(isnull(test.%s.a))`, t1, t1), fmt.Sprintf(` └─TableFullScan 10000.00 cop[tikv] table:%s keep order:false, stats:pseudo`, t1), )) @@ -797,10 +797,10 @@ func TestVectorizedMergeJoin(t *testing.T) { t1, t2, t1, t2, t1, t2, t1, t2, )).Check(testkit.Rows( fmt.Sprintf(`HashJoin 4150.01 root inner join, equal:[eq(test.%s.a, test.%s.a)]`, t1, t2), - fmt.Sprintf(`├─TableReader(Build) 3320.01 root data:Selection`), + `├─TableReader(Build) 3320.01 root data:Selection`, fmt.Sprintf(`│ └─Selection 3320.01 cop[tikv] lt(test.%s.b, 5), not(isnull(test.%s.a))`, t2, t2), fmt.Sprintf(`│ └─TableFullScan 10000.00 cop[tikv] table:%s keep order:false, stats:pseudo`, t2), - fmt.Sprintf(`└─TableReader(Probe) 3330.00 root data:Selection`), + `└─TableReader(Probe) 3330.00 root data:Selection`, fmt.Sprintf(` └─Selection 3330.00 cop[tikv] gt(test.%s.b, 5), not(isnull(test.%s.a))`, t1, t1), fmt.Sprintf(` └─TableFullScan 10000.00 cop[tikv] table:%s keep order:false, stats:pseudo`, t1), )) @@ -903,14 +903,14 @@ func TestVectorizedShuffleMergeJoin(t *testing.T) { tk.MustQuery(fmt.Sprintf("explain format = 'brief' select /*+ TIDB_SMJ(%s, %s) */ * from %s, %s where %s.a=%s.a and %s.b>5 and %s.b<5", t1, t2, t1, t2, t1, t2, t1, t2, )).Check(testkit.Rows( - fmt.Sprintf(`Shuffle 4150.01 root execution info: concurrency:4, data sources:[TableReader TableReader]`), + `Shuffle 4150.01 root execution info: concurrency:4, data sources:[TableReader TableReader]`, fmt.Sprintf(`└─MergeJoin 4150.01 root inner join, left key:test.%s.a, right key:test.%s.a`, t1, t2), fmt.Sprintf(` ├─Sort(Build) 3320.01 root test.%s.a`, t2), - fmt.Sprintf(` │ └─TableReader 3320.01 root data:Selection`), + ` │ └─TableReader 3320.01 root data:Selection`, fmt.Sprintf(` │ └─Selection 3320.01 cop[tikv] lt(test.%s.b, 5), not(isnull(test.%s.a))`, t2, t2), fmt.Sprintf(` │ └─TableFullScan 10000.00 cop[tikv] table:%s keep order:false, stats:pseudo`, t2), fmt.Sprintf(` └─Sort(Probe) 3330.00 root test.%s.a`, t1), - fmt.Sprintf(` └─TableReader 3330.00 root data:Selection`), + ` └─TableReader 3330.00 root data:Selection`, fmt.Sprintf(` └─Selection 3330.00 cop[tikv] gt(test.%s.b, 5), not(isnull(test.%s.a))`, t1, t1), fmt.Sprintf(` └─TableFullScan 10000.00 cop[tikv] table:%s keep order:false, stats:pseudo`, t1), )) @@ -918,10 +918,10 @@ func TestVectorizedShuffleMergeJoin(t *testing.T) { t1, t2, t1, t2, t1, t2, t1, t2, )).Check(testkit.Rows( fmt.Sprintf(`HashJoin 4150.01 root inner join, equal:[eq(test.%s.a, test.%s.a)]`, t1, t2), - fmt.Sprintf(`├─TableReader(Build) 3320.01 root data:Selection`), + `├─TableReader(Build) 3320.01 root data:Selection`, fmt.Sprintf(`│ └─Selection 3320.01 cop[tikv] lt(test.%s.b, 5), not(isnull(test.%s.a))`, t2, t2), fmt.Sprintf(`│ └─TableFullScan 10000.00 cop[tikv] table:%s keep order:false, stats:pseudo`, t2), - fmt.Sprintf(`└─TableReader(Probe) 3330.00 root data:Selection`), + `└─TableReader(Probe) 3330.00 root data:Selection`, fmt.Sprintf(` └─Selection 3330.00 cop[tikv] gt(test.%s.b, 5), not(isnull(test.%s.a))`, t1, t1), fmt.Sprintf(` └─TableFullScan 10000.00 cop[tikv] table:%s keep order:false, stats:pseudo`, t1), )) diff --git a/expression/builtin_compare.go b/expression/builtin_compare.go index 3fc5c9a58adf0..6ef85a4b9c057 100644 --- a/expression/builtin_compare.go +++ b/expression/builtin_compare.go @@ -2540,21 +2540,21 @@ func (b *builtinNullEQIntSig) evalInt(row chunk.Row) (val int64, isNull bool, er case isNull0 && isNull1: res = 1 case isNull0 != isNull1: - break + return res, false, nil case isUnsigned0 && isUnsigned1 && types.CompareUint64(uint64(arg0), uint64(arg1)) == 0: res = 1 case !isUnsigned0 && !isUnsigned1 && types.CompareInt64(arg0, arg1) == 0: res = 1 case isUnsigned0 && !isUnsigned1: if arg1 < 0 { - break + return res, false, nil } if types.CompareInt64(arg0, arg1) == 0 { res = 1 } case !isUnsigned0 && isUnsigned1: if arg0 < 0 { - break + return res, false, nil } if types.CompareInt64(arg0, arg1) == 0 { res = 1 @@ -2587,7 +2587,7 @@ func (b *builtinNullEQRealSig) evalInt(row chunk.Row) (val int64, isNull bool, e case isNull0 && isNull1: res = 1 case isNull0 != isNull1: - break + return res, false, nil case types.CompareFloat64(arg0, arg1) == 0: res = 1 } @@ -2618,7 +2618,7 @@ func (b *builtinNullEQDecimalSig) evalInt(row chunk.Row) (val int64, isNull bool case isNull0 && isNull1: res = 1 case isNull0 != isNull1: - break + return res, false, nil case arg0.Compare(arg1) == 0: res = 1 } @@ -2649,7 +2649,7 @@ func (b *builtinNullEQStringSig) evalInt(row chunk.Row) (val int64, isNull bool, case isNull0 && isNull1: res = 1 case isNull0 != isNull1: - break + return res, false, nil case types.CompareString(arg0, arg1, b.collation) == 0: res = 1 } @@ -2680,7 +2680,7 @@ func (b *builtinNullEQDurationSig) evalInt(row chunk.Row) (val int64, isNull boo case isNull0 && isNull1: res = 1 case isNull0 != isNull1: - break + return res, false, nil case arg0.Compare(arg1) == 0: res = 1 } @@ -2711,7 +2711,7 @@ func (b *builtinNullEQTimeSig) evalInt(row chunk.Row) (val int64, isNull bool, e case isNull0 && isNull1: res = 1 case isNull0 != isNull1: - break + return res, false, nil case arg0.Compare(arg1) == 0: res = 1 } @@ -2742,7 +2742,7 @@ func (b *builtinNullEQJSONSig) evalInt(row chunk.Row) (val int64, isNull bool, e case isNull0 && isNull1: res = 1 case isNull0 != isNull1: - break + return res, false, nil default: cmpRes := json.CompareBinary(arg0, arg1) if cmpRes == 0 { diff --git a/infoschema/cluster.go b/infoschema/cluster.go index d1d4f3c5a7fac..47bb7db4c3434 100644 --- a/infoschema/cluster.go +++ b/infoschema/cluster.go @@ -79,16 +79,14 @@ func isClusterTableByName(dbName, tableName string) bool { dbName = strings.ToUpper(dbName) switch dbName { case util.InformationSchemaName.O, util.PerformanceSchemaName.O: - break - default: - return false - } - tableName = strings.ToUpper(tableName) - for _, name := range memTableToClusterTables { - name = strings.ToUpper(name) - if name == tableName { - return true + tableName = strings.ToUpper(tableName) + for _, name := range memTableToClusterTables { + name = strings.ToUpper(name) + if name == tableName { + return true + } } + default: } return false } diff --git a/parser/ast/misc.go b/parser/ast/misc.go index 3ec7d5c753ba8..38c465568634a 100644 --- a/parser/ast/misc.go +++ b/parser/ast/misc.go @@ -619,7 +619,6 @@ const ( func (n CompletionType) Restore(ctx *format.RestoreCtx) error { switch n { case CompletionTypeDefault: - break case CompletionTypeChain: ctx.WriteKeyWord(" AND CHAIN") case CompletionTypeRelease: diff --git a/parser/lexer.go b/parser/lexer.go index 659fc14dd9235..bcddc5f5bfcea 100644 --- a/parser/lexer.go +++ b/parser/lexer.go @@ -478,7 +478,6 @@ func startWithSlash(s *Scanner) (tok int, pos Pos, lit string) { } case 'M': // '/*M' maybe MariaDB-specific comments // no special treatment for now. - break case '+': // '/*+' optimizer hints // See https://dev.mysql.com/doc/refman/5.7/en/optimizer-hints.html @@ -502,7 +501,6 @@ func startWithSlash(s *Scanner) (tok int, pos Pos, lit string) { currentCharIsStar = true default: - break } // standard C-like comment. read until we see '*/' then drop it. @@ -574,7 +572,7 @@ func startWithAt(s *Scanner) (tok int, pos Pos, lit string) { tok, lit = doubleAtIdentifier, s.r.data(&pos) } case invalid: - break + return default: tok = singleAtIdentifier } diff --git a/parser/model/ddl.go b/parser/model/ddl.go index 549a8119e6b33..993c2c485f50c 100644 --- a/parser/model/ddl.go +++ b/parser/model/ddl.go @@ -202,9 +202,7 @@ func (h *HistoryInfo) AddTableInfo(schemaVer int64, tblInfo *TableInfo) { func (h *HistoryInfo) SetTableInfos(schemaVer int64, tblInfos []*TableInfo) { h.SchemaVersion = schemaVer h.MultipleTableInfos = make([]*TableInfo, len(tblInfos)) - for i, info := range tblInfos { - h.MultipleTableInfos[i] = info - } + copy(h.MultipleTableInfos, tblInfos) } // Clean cleans history information. diff --git a/parser/types/etc.go b/parser/types/etc.go index 2fe3d113e8820..1fdfeaf05367f 100644 --- a/parser/types/etc.go +++ b/parser/types/etc.go @@ -128,12 +128,8 @@ func TypeToStr(tp byte, cs string) (r string) { // Args: // ts: type string func StrToType(ts string) (tp byte) { - if strings.Contains(ts, "blob") { - ts = strings.Replace(ts, "blob", "text", 1) - } else if strings.Contains(ts, "binary") { - ts = strings.Replace(ts, "binary", "char", 1) - } - + ts = strings.Replace(ts, "blob", "text", 1) + ts = strings.Replace(ts, "binary", "char", 1) if tp, ok := str2Type[ts]; ok { return tp } diff --git a/util/column-mapping/column.go b/util/column-mapping/column.go index e276b0004882c..93a1443dc6173 100644 --- a/util/column-mapping/column.go +++ b/util/column-mapping/column.go @@ -112,7 +112,7 @@ func (r *Rule) Valid() error { if r.Expression == PartitionID { switch len(r.Arguments) { case 3, 4: - break + return nil default: return errors.NotValidf("arguments %v for patition id", r.Arguments) }