Skip to content

Commit

Permalink
Enable more golang-ci linters (github#1149)
Browse files Browse the repository at this point in the history
  • Loading branch information
timvaillancourt authored and RainbowDashy committed Dec 13, 2022
1 parent bb7e561 commit 1d35859
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 23 deletions.
15 changes: 14 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,21 @@ linters:
disable:
- errcheck
enable:
- contextcheck
- durationcheck
- errname
- execinquery
- gofmt
- ifshort
- misspell
- nilerr
- noctx
- nolintlint
- nosprintfhostport
- prealloc
- rowserrcheck
- sqlclosecheck
- unconvert
- unused

- wastedassign
- whitespace
7 changes: 3 additions & 4 deletions go/cmd/gh-ost/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ func main() {
}
if *askPass {
fmt.Println("Password:")
bytePassword, err := term.ReadPassword(int(syscall.Stdin))
bytePassword, err := term.ReadPassword(syscall.Stdin)
if err != nil {
migrationContext.Log.Fatale(err)
}
Expand Down Expand Up @@ -301,10 +301,9 @@ func main() {
acceptSignals(migrationContext)

migrator := logic.NewMigrator(migrationContext, AppVersion)
err := migrator.Migrate()
if err != nil {
if err := migrator.Migrate(); err != nil {
migrator.ExecOnFailureHook()
migrationContext.Log.Fatale(err)
}
fmt.Fprintf(os.Stdout, "# Done\n")
fmt.Fprintln(os.Stdout, "# Done")
}
1 change: 0 additions & 1 deletion go/logic/applier.go
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,6 @@ func (this *Applier) buildDMLEventQuery(dmlEvent *binlog.BinlogDMLEvent) (result

// ApplyDMLEventQueries applies multiple DML queries onto the _ghost_ table
func (this *Applier) ApplyDMLEventQueries(dmlEvents [](*binlog.BinlogDMLEvent)) error {

var totalDelta int64

err := func() error {
Expand Down
4 changes: 2 additions & 2 deletions go/logic/migrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,7 @@ func (this *Migrator) printStatus(rule PrintStatusRule, writers ...io.Writer) {
state = fmt.Sprintf("throttled, %s", throttleReason)
}

shouldPrintStatus := false
var shouldPrintStatus bool
if rule == HeuristicPrintStatusRule {
if elapsedSeconds <= 60 {
shouldPrintStatus = true
Expand Down Expand Up @@ -1298,7 +1298,7 @@ func (this *Migrator) executeWriteFuncs() error {
if niceRatio := this.migrationContext.GetNiceRatio(); niceRatio > 0 {
copyRowsDuration := time.Since(copyRowsStartTime)
sleepTimeNanosecondFloat64 := niceRatio * float64(copyRowsDuration.Nanoseconds())
sleepTime := time.Duration(time.Duration(int64(sleepTimeNanosecondFloat64)) * time.Nanosecond)
sleepTime := time.Duration(int64(sleepTimeNanosecondFloat64)) * time.Nanosecond
time.Sleep(sleepTime)
}
}
Expand Down
4 changes: 1 addition & 3 deletions go/logic/server.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2021 GitHub Inc.
Copyright 2022 GitHub Inc.
See https://github.com/github/gh-ost/blob/master/LICENSE
*/

Expand Down Expand Up @@ -122,8 +122,6 @@ func (this *Server) onServerCommand(command string, writer *bufio.Writer) (err e

// applyServerCommand parses and executes commands by user
func (this *Server) applyServerCommand(command string, writer *bufio.Writer) (printStatusRule PrintStatusRule, err error) {
printStatusRule = NoPrintStatusRule

tokens := strings.SplitN(command, "=", 2)
command = strings.TrimSpace(tokens[0])
arg := ""
Expand Down
1 change: 0 additions & 1 deletion go/logic/streamer.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ func NewEventsStreamer(migrationContext *base.MigrationContext) *EventsStreamer
// AddListener registers a new listener for binlog events, on a per-table basis
func (this *EventsStreamer) AddListener(
async bool, databaseName string, tableName string, onDmlEvent func(event *binlog.BinlogDMLEvent) error) (err error) {

this.listenersMutex.Lock()
defer this.listenersMutex.Unlock()

Expand Down
1 change: 0 additions & 1 deletion go/logic/throttler.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ func (this *Throttler) collectReplicationLag(firstThrottlingCollected chan<- boo

// collectControlReplicasLag polls all the control replicas to get maximum lag value
func (this *Throttler) collectControlReplicasLag() {

if atomic.LoadInt64(&this.migrationContext.HibernateUntil) > 0 {
return
}
Expand Down
3 changes: 1 addition & 2 deletions go/mysql/instance_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ const detachHint = "//"

// ParseInstanceKey will parse an InstanceKey from a string representation such as 127.0.0.1:3306
func NewRawInstanceKey(hostPort string) (*InstanceKey, error) {
hostname := ""
port := ""
var hostname, port string
if submatch := ipv4HostPortRegexp.FindStringSubmatch(hostPort); len(submatch) > 0 {
hostname = submatch[1]
port = submatch[2]
Expand Down
2 changes: 1 addition & 1 deletion go/sql/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ func BuildRangeComparison(columns []string, values []string, args []interface{},
if includeEquals {
comparison, err := BuildEqualsComparison(columns, values)
if err != nil {
return "", explodedArgs, nil
return "", explodedArgs, err
}
comparisons = append(comparisons, comparison)
explodedArgs = append(explodedArgs, args...)
Expand Down
3 changes: 1 addition & 2 deletions go/sql/parser.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright 2016 GitHub Inc.
Copyright 2022 GitHub Inc.
See https://github.com/github/gh-ost/blob/master/LICENSE
*/

Expand Down Expand Up @@ -135,7 +135,6 @@ func (this *AlterTableParser) parseAlterToken(alterToken string) (err error) {
}

func (this *AlterTableParser) ParseAlterStatement(alterStatement string) (err error) {

this.alterStatementOptions = alterStatement
for _, alterTableRegexp := range alterTableExplicitSchemaTableRegexps {
if submatch := alterTableRegexp.FindStringSubmatch(this.alterStatementOptions); len(submatch) > 0 {
Expand Down