Enable more golang-ci linters (#1149)

This commit is contained in:
Tim Vaillancourt 2022-07-18 18:37:18 +02:00 committed by GitHub
parent 84dca03311
commit ffe54f48ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 24 additions and 23 deletions

View File

@ -4,8 +4,21 @@ linters:
disable: disable:
- errcheck - errcheck
enable: enable:
- contextcheck
- durationcheck
- errname
- execinquery
- gofmt
- ifshort
- misspell
- nilerr
- noctx - noctx
- nolintlint
- nosprintfhostport
- prealloc
- rowserrcheck - rowserrcheck
- sqlclosecheck - sqlclosecheck
- unconvert
- unused - unused
- wastedassign
- whitespace

View File

@ -270,7 +270,7 @@ func main() {
} }
if *askPass { if *askPass {
fmt.Println("Password:") fmt.Println("Password:")
bytePassword, err := term.ReadPassword(int(syscall.Stdin)) bytePassword, err := term.ReadPassword(syscall.Stdin)
if err != nil { if err != nil {
migrationContext.Log.Fatale(err) migrationContext.Log.Fatale(err)
} }
@ -300,10 +300,9 @@ func main() {
acceptSignals(migrationContext) acceptSignals(migrationContext)
migrator := logic.NewMigrator(migrationContext, AppVersion) migrator := logic.NewMigrator(migrationContext, AppVersion)
err := migrator.Migrate() if err := migrator.Migrate(); err != nil {
if err != nil {
migrator.ExecOnFailureHook() migrator.ExecOnFailureHook()
migrationContext.Log.Fatale(err) migrationContext.Log.Fatale(err)
} }
fmt.Fprintf(os.Stdout, "# Done\n") fmt.Fprintln(os.Stdout, "# Done")
} }

View File

@ -1042,7 +1042,6 @@ func (this *Applier) buildDMLEventQuery(dmlEvent *binlog.BinlogDMLEvent) (result
// ApplyDMLEventQueries applies multiple DML queries onto the _ghost_ table // ApplyDMLEventQueries applies multiple DML queries onto the _ghost_ table
func (this *Applier) ApplyDMLEventQueries(dmlEvents [](*binlog.BinlogDMLEvent)) error { func (this *Applier) ApplyDMLEventQueries(dmlEvents [](*binlog.BinlogDMLEvent)) error {
var totalDelta int64 var totalDelta int64
err := func() error { err := func() error {

View File

@ -978,7 +978,7 @@ func (this *Migrator) printStatus(rule PrintStatusRule, writers ...io.Writer) {
state = fmt.Sprintf("throttled, %s", throttleReason) state = fmt.Sprintf("throttled, %s", throttleReason)
} }
shouldPrintStatus := false var shouldPrintStatus bool
if rule == HeuristicPrintStatusRule { if rule == HeuristicPrintStatusRule {
if elapsedSeconds <= 60 { if elapsedSeconds <= 60 {
shouldPrintStatus = true shouldPrintStatus = true
@ -1292,7 +1292,7 @@ func (this *Migrator) executeWriteFuncs() error {
if niceRatio := this.migrationContext.GetNiceRatio(); niceRatio > 0 { if niceRatio := this.migrationContext.GetNiceRatio(); niceRatio > 0 {
copyRowsDuration := time.Since(copyRowsStartTime) copyRowsDuration := time.Since(copyRowsStartTime)
sleepTimeNanosecondFloat64 := niceRatio * float64(copyRowsDuration.Nanoseconds()) sleepTimeNanosecondFloat64 := niceRatio * float64(copyRowsDuration.Nanoseconds())
sleepTime := time.Duration(time.Duration(int64(sleepTimeNanosecondFloat64)) * time.Nanosecond) sleepTime := time.Duration(int64(sleepTimeNanosecondFloat64)) * time.Nanosecond
time.Sleep(sleepTime) time.Sleep(sleepTime)
} }
} }

View File

@ -1,5 +1,5 @@
/* /*
Copyright 2021 GitHub Inc. Copyright 2022 GitHub Inc.
See https://github.com/github/gh-ost/blob/master/LICENSE See https://github.com/github/gh-ost/blob/master/LICENSE
*/ */
@ -122,8 +122,6 @@ func (this *Server) onServerCommand(command string, writer *bufio.Writer) (err e
// applyServerCommand parses and executes commands by user // applyServerCommand parses and executes commands by user
func (this *Server) applyServerCommand(command string, writer *bufio.Writer) (printStatusRule PrintStatusRule, err error) { func (this *Server) applyServerCommand(command string, writer *bufio.Writer) (printStatusRule PrintStatusRule, err error) {
printStatusRule = NoPrintStatusRule
tokens := strings.SplitN(command, "=", 2) tokens := strings.SplitN(command, "=", 2)
command = strings.TrimSpace(tokens[0]) command = strings.TrimSpace(tokens[0])
arg := "" arg := ""

View File

@ -59,7 +59,6 @@ func NewEventsStreamer(migrationContext *base.MigrationContext) *EventsStreamer
// AddListener registers a new listener for binlog events, on a per-table basis // AddListener registers a new listener for binlog events, on a per-table basis
func (this *EventsStreamer) AddListener( func (this *EventsStreamer) AddListener(
async bool, databaseName string, tableName string, onDmlEvent func(event *binlog.BinlogDMLEvent) error) (err error) { async bool, databaseName string, tableName string, onDmlEvent func(event *binlog.BinlogDMLEvent) error) (err error) {
this.listenersMutex.Lock() this.listenersMutex.Lock()
defer this.listenersMutex.Unlock() defer this.listenersMutex.Unlock()

View File

@ -180,7 +180,6 @@ func (this *Throttler) collectReplicationLag(firstThrottlingCollected chan<- boo
// collectControlReplicasLag polls all the control replicas to get maximum lag value // collectControlReplicasLag polls all the control replicas to get maximum lag value
func (this *Throttler) collectControlReplicasLag() { func (this *Throttler) collectControlReplicasLag() {
if atomic.LoadInt64(&this.migrationContext.HibernateUntil) > 0 { if atomic.LoadInt64(&this.migrationContext.HibernateUntil) > 0 {
return return
} }

View File

@ -35,8 +35,7 @@ const detachHint = "//"
// ParseInstanceKey will parse an InstanceKey from a string representation such as 127.0.0.1:3306 // ParseInstanceKey will parse an InstanceKey from a string representation such as 127.0.0.1:3306
func NewRawInstanceKey(hostPort string) (*InstanceKey, error) { func NewRawInstanceKey(hostPort string) (*InstanceKey, error) {
hostname := "" var hostname, port string
port := ""
if submatch := ipv4HostPortRegexp.FindStringSubmatch(hostPort); len(submatch) > 0 { if submatch := ipv4HostPortRegexp.FindStringSubmatch(hostPort); len(submatch) > 0 {
hostname = submatch[1] hostname = submatch[1]
port = submatch[2] port = submatch[2]

View File

@ -167,7 +167,7 @@ func BuildRangeComparison(columns []string, values []string, args []interface{},
if includeEquals { if includeEquals {
comparison, err := BuildEqualsComparison(columns, values) comparison, err := BuildEqualsComparison(columns, values)
if err != nil { if err != nil {
return "", explodedArgs, nil return "", explodedArgs, err
} }
comparisons = append(comparisons, comparison) comparisons = append(comparisons, comparison)
explodedArgs = append(explodedArgs, args...) explodedArgs = append(explodedArgs, args...)

View File

@ -1,5 +1,5 @@
/* /*
Copyright 2016 GitHub Inc. Copyright 2022 GitHub Inc.
See https://github.com/github/gh-ost/blob/master/LICENSE See https://github.com/github/gh-ost/blob/master/LICENSE
*/ */
@ -135,7 +135,6 @@ func (this *AlterTableParser) parseAlterToken(alterToken string) (err error) {
} }
func (this *AlterTableParser) ParseAlterStatement(alterStatement string) (err error) { func (this *AlterTableParser) ParseAlterStatement(alterStatement string) (err error) {
this.alterStatementOptions = alterStatement this.alterStatementOptions = alterStatement
for _, alterTableRegexp := range alterTableExplicitSchemaTableRegexps { for _, alterTableRegexp := range alterTableExplicitSchemaTableRegexps {
if submatch := alterTableRegexp.FindStringSubmatch(this.alterStatementOptions); len(submatch) > 0 { if submatch := alterTableRegexp.FindStringSubmatch(this.alterStatementOptions); len(submatch) > 0 {

View File

@ -1,5 +1,5 @@
/* /*
Copyright 2016 GitHub Inc. Copyright 2022 GitHub Inc.
See https://github.com/github/gh-ost/blob/master/LICENSE See https://github.com/github/gh-ost/blob/master/LICENSE
*/ */
@ -40,7 +40,6 @@ func TestParseAlterStatementTrivialRename(t *testing.T) {
} }
func TestParseAlterStatementWithAutoIncrement(t *testing.T) { func TestParseAlterStatementWithAutoIncrement(t *testing.T) {
statements := []string{ statements := []string{
"auto_increment=7", "auto_increment=7",
"auto_increment = 7", "auto_increment = 7",
@ -150,7 +149,6 @@ func TestSanitizeQuotesFromAlterStatement(t *testing.T) {
} }
func TestParseAlterStatementDroppedColumns(t *testing.T) { func TestParseAlterStatementDroppedColumns(t *testing.T) {
{ {
parser := NewAlterTableParser() parser := NewAlterTableParser()
statement := "drop column b" statement := "drop column b"
@ -190,7 +188,6 @@ func TestParseAlterStatementDroppedColumns(t *testing.T) {
} }
func TestParseAlterStatementRenameTable(t *testing.T) { func TestParseAlterStatementRenameTable(t *testing.T) {
{ {
parser := NewAlterTableParser() parser := NewAlterTableParser()
statement := "drop column b" statement := "drop column b"
@ -230,7 +227,6 @@ func TestParseAlterStatementRenameTable(t *testing.T) {
} }
func TestParseAlterStatementExplicitTable(t *testing.T) { func TestParseAlterStatementExplicitTable(t *testing.T) {
{ {
parser := NewAlterTableParser() parser := NewAlterTableParser()
statement := "drop column b" statement := "drop column b"