Skip to content

Commit

Permalink
linter: Convert untagged switch to tagged switch (#44429)
Browse files Browse the repository at this point in the history
ref #40786
  • Loading branch information
hawkingrei authored Jun 6, 2023
1 parent e3249e8 commit f470c91
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 596 deletions.
12 changes: 6 additions & 6 deletions br/pkg/lightning/common/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -357,10 +357,10 @@ func TableExists(ctx context.Context, db utils.QueryExecutor, schema, table stri
query := "SELECT 1 from INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = ? AND TABLE_NAME = ?"
var exist string
err := db.QueryRowContext(ctx, query, schema, table).Scan(&exist)
switch {
case err == nil:
switch err {
case nil:
return true, nil
case err == sql.ErrNoRows:
case sql.ErrNoRows:
return false, nil
default:
return false, errors.Annotatef(err, "check table exists failed")
Expand All @@ -372,10 +372,10 @@ func SchemaExists(ctx context.Context, db utils.QueryExecutor, schema string) (b
query := "SELECT 1 from INFORMATION_SCHEMA.SCHEMATA WHERE SCHEMA_NAME = ?"
var exist string
err := db.QueryRowContext(ctx, query, schema).Scan(&exist)
switch {
case err == nil:
switch err {
case nil:
return true, nil
case err == sql.ErrNoRows:
case sql.ErrNoRows:
return false, nil
default:
return false, errors.Annotatef(err, "check schema exists failed")
Expand Down
3 changes: 1 addition & 2 deletions br/pkg/restore/systable_restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,7 @@ func (rc *Client) getDatabaseByName(name string) (*database, bool) {
func (rc *Client) afterSystemTablesReplaced(tables []string) error {
var err error
for _, table := range tables {
switch {
case table == "user":
if table == "user" {
if rc.fullClusterRestore {
log.Info("privilege system table restored, please reconnect to make it effective")
err = rc.dom.NotifyUpdatePrivilege()
Expand Down
1 change: 1 addition & 0 deletions build/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ STATICHECK_ANALYZERS = [
"SA6001",
"SA6002",
"SA6005",
"QF1002",
"U1000",
]

Expand Down
7 changes: 7 additions & 0 deletions build/nogo_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -1178,5 +1178,12 @@
".*_test.go": "ignore test code",
"external/": "no need to vet third party code"
}
},
"QF1002": {
"exclude_files": {
"parser/parser.go": "parser/parser.go code",
".*_test.go": "ignore test code",
"external/": "no need to vet third party code"
}
}
}
49 changes: 24 additions & 25 deletions privilege/privileges/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -746,8 +746,7 @@ func (p *MySQLPrivilege) decodeUserTableRow(row chunk.Row, fs []*ast.ResultField
func (p *MySQLPrivilege) decodeGlobalPrivTableRow(row chunk.Row, fs []*ast.ResultField) error {
var value globalPrivRecord
for i, f := range fs {
switch {
case f.ColumnAsName.L == "priv":
if f.ColumnAsName.L == "priv" {
privData := row.GetString(i)
if len(privData) > 0 {
var privValue GlobalPrivValue
Expand All @@ -770,7 +769,7 @@ func (p *MySQLPrivilege) decodeGlobalPrivTableRow(row chunk.Row, fs []*ast.Resul
}
}
}
default:
} else {
value.assignUserOrHost(row, i, f)
}
}
Expand All @@ -784,10 +783,10 @@ func (p *MySQLPrivilege) decodeGlobalPrivTableRow(row chunk.Row, fs []*ast.Resul
func (p *MySQLPrivilege) decodeGlobalGrantsTableRow(row chunk.Row, fs []*ast.ResultField) error {
var value dynamicPrivRecord
for i, f := range fs {
switch {
case f.ColumnAsName.L == "priv":
switch f.ColumnAsName.L {
case "priv":
value.PrivilegeName = strings.ToUpper(row.GetString(i))
case f.ColumnAsName.L == "with_grant_option":
case "with_grant_option":
value.GrantOption = row.GetEnum(i).String() == "Y"
default:
value.assignUserOrHost(row, i, f)
Expand Down Expand Up @@ -827,14 +826,14 @@ func (p *MySQLPrivilege) decodeDBTableRow(row chunk.Row, fs []*ast.ResultField)
func (p *MySQLPrivilege) decodeTablesPrivTableRow(row chunk.Row, fs []*ast.ResultField) error {
var value tablesPrivRecord
for i, f := range fs {
switch {
case f.ColumnAsName.L == "db":
switch f.ColumnAsName.L {
case "db":
value.DB = row.GetString(i)
case f.ColumnAsName.L == "table_name":
case "table_name":
value.TableName = row.GetString(i)
case f.ColumnAsName.L == "table_priv":
case "table_priv":
value.TablePriv = decodeSetToPrivilege(row.GetSet(i))
case f.ColumnAsName.L == "column_priv":
case "column_priv":
value.ColumnPriv = decodeSetToPrivilege(row.GetSet(i))
default:
value.assignUserOrHost(row, i, f)
Expand All @@ -847,14 +846,14 @@ func (p *MySQLPrivilege) decodeTablesPrivTableRow(row chunk.Row, fs []*ast.Resul
func (p *MySQLPrivilege) decodeRoleEdgesTable(row chunk.Row, fs []*ast.ResultField) error {
var fromUser, fromHost, toHost, toUser string
for i, f := range fs {
switch {
case f.ColumnAsName.L == "from_host":
switch f.ColumnAsName.L {
case "from_host":
fromHost = row.GetString(i)
case f.ColumnAsName.L == "from_user":
case "from_user":
fromUser = row.GetString(i)
case f.ColumnAsName.L == "to_host":
case "to_host":
toHost = row.GetString(i)
case f.ColumnAsName.L == "to_user":
case "to_user":
toUser = row.GetString(i)
}
}
Expand All @@ -872,10 +871,10 @@ func (p *MySQLPrivilege) decodeRoleEdgesTable(row chunk.Row, fs []*ast.ResultFie
func (p *MySQLPrivilege) decodeDefaultRoleTableRow(row chunk.Row, fs []*ast.ResultField) error {
var value defaultRoleRecord
for i, f := range fs {
switch {
case f.ColumnAsName.L == "default_role_host":
switch f.ColumnAsName.L {
case "default_role_host":
value.DefaultRoleHost = row.GetString(i)
case f.ColumnAsName.L == "default_role_user":
case "default_role_user":
value.DefaultRoleUser = row.GetString(i)
default:
value.assignUserOrHost(row, i, f)
Expand All @@ -888,20 +887,20 @@ func (p *MySQLPrivilege) decodeDefaultRoleTableRow(row chunk.Row, fs []*ast.Resu
func (p *MySQLPrivilege) decodeColumnsPrivTableRow(row chunk.Row, fs []*ast.ResultField) error {
var value columnsPrivRecord
for i, f := range fs {
switch {
case f.ColumnAsName.L == "db":
switch f.ColumnAsName.L {
case "db":
value.DB = row.GetString(i)
case f.ColumnAsName.L == "table_name":
case "table_name":
value.TableName = row.GetString(i)
case f.ColumnAsName.L == "column_name":
case "column_name":
value.ColumnName = row.GetString(i)
case f.ColumnAsName.L == "timestamp":
case "timestamp":
var err error
value.Timestamp, err = row.GetTime(i).GoTime(time.Local)
if err != nil {
return errors.Trace(err)
}
case f.ColumnAsName.L == "column_priv":
case "column_priv":
value.ColumnPriv = decodeSetToPrivilege(row.GetSet(i))
default:
value.assignUserOrHost(row, i, f)
Expand Down
26 changes: 0 additions & 26 deletions resourcemanager/pooltask/BUILD.bazel

This file was deleted.

180 changes: 0 additions & 180 deletions resourcemanager/pooltask/task.go

This file was deleted.

Loading

0 comments on commit f470c91

Please sign in to comment.