Skip to content

golangci-lint 2 #1024

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

Merged
merged 1 commit into from
Apr 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ jobs:
with:
go-version: stable
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
uses: golangci/golangci-lint-action@v7
with:
version: latest
args: --timeout=3m
Expand Down
58 changes: 35 additions & 23 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,35 +1,47 @@
version: "2"
linters:
disable-all: true
default: none
enable:
# All code is ready for:
- errcheck
- gofumpt
- goimports
- govet
- gosimple
- ineffassign
- misspell
- nakedret
- nolintlint
- staticcheck
- typecheck
- unconvert
- unused
- whitespace
# ToDo:
#- gocritic
#- golint
linters-settings:
nolintlint:
allow-unused: false
require-specific: true

govet:
enable-all: true
disable:
- fieldalignment
- lostcancel
- shadow
issues:
exclude-files:
- client/examples_test.go
settings:
govet:
disable:
- fieldalignment
- lostcancel
- shadow
enable-all: true
nolintlint:
require-specific: true
allow-unused: false
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
paths:
- client/examples_test.go
- third_party$
- builtin$
- examples$
formatters:
enable:
- gofumpt
- goimports
exclusions:
generated: lax
paths:
- client/examples_test.go
- third_party$
- builtin$
- examples$
8 changes: 4 additions & 4 deletions client/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,9 @@ func ConnectWithDialer(ctx context.Context, network, addr, user, password, dbNam

c.Conn = packet.NewConnWithTimeout(conn, c.ReadTimeout, c.WriteTimeout, c.BufferSize)
if c.tlsConfig != nil {
seq := c.Conn.Sequence
seq := c.Sequence
c.Conn = packet.NewTLSConnWithTimeout(conn, c.ReadTimeout, c.WriteTimeout)
c.Conn.Sequence = seq
c.Sequence = seq
}

if err = c.handshake(); err != nil {
Expand All @@ -163,9 +163,9 @@ func ConnectWithDialer(ctx context.Context, network, addr, user, password, dbNam
}

if c.ccaps&mysql.CLIENT_COMPRESS > 0 {
c.Conn.Compression = mysql.MYSQL_COMPRESS_ZLIB
c.Compression = mysql.MYSQL_COMPRESS_ZLIB
} else if c.ccaps&mysql.CLIENT_ZSTD_COMPRESSION_ALGORITHM > 0 {
c.Conn.Compression = mysql.MYSQL_COMPRESS_ZSTD
c.Compression = mysql.MYSQL_COMPRESS_ZSTD
}

// if a collation was set with a ID of > 255, then we need to call SET NAMES ...
Expand Down
6 changes: 3 additions & 3 deletions client/conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,14 @@ func (s *connTestSuite) TestExecuteMultiple() {
// also, since this is not the last query, the SERVER_MORE_RESULTS_EXISTS
// flag should be set
require.True(s.T(), result.Status&mysql.SERVER_MORE_RESULTS_EXISTS > 0)
require.Equal(s.T(), 0, result.Resultset.RowNumber())
require.Equal(s.T(), 0, result.RowNumber())
require.Equal(s.T(), uint64(1), result.AffectedRows)
require.NoError(s.T(), err)
case 1:
// the SELECT query should have an resultset
// still not the last query, flag should be set
require.True(s.T(), result.Status&mysql.SERVER_MORE_RESULTS_EXISTS > 0)
require.Greater(s.T(), result.Resultset.RowNumber(), 0)
require.Greater(s.T(), result.RowNumber(), 0)
require.NoError(s.T(), err)
case 3:
// this query is obviously bogus so the error should be non-nil
Expand Down Expand Up @@ -175,7 +175,7 @@ func (s *connTestSuite) TestExecuteSelectStreaming() {
// result.Resultset must be defined at this point
require.NotNil(s.T(), result.Resultset)
// Check number of columns
require.Len(s.T(), result.Resultset.Fields, colsInResult)
require.Len(s.T(), result.Fields, colsInResult)

perResultCallbackCalledTimes++
return nil
Expand Down
23 changes: 13 additions & 10 deletions client/resp.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,16 @@ func (c *Conn) handleAuthResult() error {
}

// handle caching_sha2_password
if c.authPluginName == mysql.AUTH_CACHING_SHA2_PASSWORD {
switch c.authPluginName {
case mysql.AUTH_CACHING_SHA2_PASSWORD:
if data == nil {
return nil // auth already succeeded
}
if data[0] == mysql.CACHE_SHA2_FAST_AUTH {
switch data[0] {
case mysql.CACHE_SHA2_FAST_AUTH:
_, err = c.readOK()
return err
} else if data[0] == mysql.CACHE_SHA2_FULL_AUTH {
case mysql.CACHE_SHA2_FULL_AUTH:
// need full authentication
if c.tlsConfig != nil || c.proto == "unix" {
if err = c.WriteClearAuthPacket(c.password); err != nil {
Expand All @@ -141,10 +143,10 @@ func (c *Conn) handleAuthResult() error {
}
_, err = c.readOK()
return err
} else {
default:
return errors.Errorf("invalid packet %x", data[0])
}
} else if c.authPluginName == mysql.AUTH_SHA256_PASSWORD {
case mysql.AUTH_SHA256_PASSWORD:
if len(data) == 0 {
return nil // auth already succeeded
}
Expand Down Expand Up @@ -205,11 +207,12 @@ func (c *Conn) readOK() (*mysql.Result, error) {
return nil, errors.Trace(err)
}

if data[0] == mysql.OK_HEADER {
switch data[0] {
case mysql.OK_HEADER:
return c.handleOKPacket(data)
} else if data[0] == mysql.ERR_HEADER {
case mysql.ERR_HEADER:
return nil, c.handleErrorPacket(data)
} else {
default:
return nil, errors.New("invalid ok packet")
}
}
Expand Down Expand Up @@ -310,7 +313,7 @@ func (c *Conn) readResultsetStreaming(data []byte, binary bool, result *mysql.Re
}

// this is a streaming resultset
result.Resultset.Streaming = mysql.StreamingSelect
result.Streaming = mysql.StreamingSelect

if err := c.readResultColumns(result); err != nil {
return errors.Trace(err)
Expand All @@ -327,7 +330,7 @@ func (c *Conn) readResultsetStreaming(data []byte, binary bool, result *mysql.Re
}

// this resultset is done streaming
result.Resultset.StreamingDone = true
result.StreamingDone = true

return nil
}
Expand Down
28 changes: 14 additions & 14 deletions driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ func (st *state) replyError(err error) error {

func (c *conn) Exec(query string, args []sqldriver.Value) (sqldriver.Result, error) {
a := buildArgs(args)
r, err := c.Conn.Execute(query, a...)
r, err := c.Execute(query, a...)
if err != nil {
return nil, c.state.replyError(err)
}
Expand All @@ -389,7 +389,7 @@ func (c *conn) Exec(query string, args []sqldriver.Value) (sqldriver.Result, err
func (c *conn) ExecContext(ctx context.Context, query string, args []sqldriver.NamedValue) (sqldriver.Result, error) {
defer c.watchCtx(ctx)()
a := buildNamedArgs(args)
r, err := c.Conn.Execute(query, a...)
r, err := c.Execute(query, a...)
if err != nil {
return nil, c.state.replyError(err)
}
Expand All @@ -398,7 +398,7 @@ func (c *conn) ExecContext(ctx context.Context, query string, args []sqldriver.N

func (c *conn) Query(query string, args []sqldriver.Value) (sqldriver.Rows, error) {
a := buildArgs(args)
r, err := c.Conn.Execute(query, a...)
r, err := c.Execute(query, a...)
if err != nil {
return nil, c.state.replyError(err)
}
Expand All @@ -408,7 +408,7 @@ func (c *conn) Query(query string, args []sqldriver.Value) (sqldriver.Rows, erro
func (c *conn) QueryContext(ctx context.Context, query string, args []sqldriver.NamedValue) (sqldriver.Rows, error) {
defer c.watchCtx(ctx)()
a := buildNamedArgs(args)
r, err := c.Conn.Execute(query, a...)
r, err := c.Execute(query, a...)
if err != nil {
return nil, c.state.replyError(err)
}
Expand All @@ -429,12 +429,12 @@ func (s *stmt) Close() error {
}

func (s *stmt) NumInput() int {
return s.Stmt.ParamNum()
return s.ParamNum()
}

func (s *stmt) Exec(args []sqldriver.Value) (sqldriver.Result, error) {
a := buildArgs(args)
r, err := s.Stmt.Execute(a...)
r, err := s.Execute(a...)
if err != nil {
return nil, s.connectionState.replyError(err)
}
Expand All @@ -445,7 +445,7 @@ func (s *stmt) ExecContext(ctx context.Context, args []sqldriver.NamedValue) (sq
defer s.watchCtx(ctx)()

a := buildNamedArgs(args)
r, err := s.Stmt.Execute(a...)
r, err := s.Execute(a...)
if err != nil {
return nil, s.connectionState.replyError(err)
}
Expand All @@ -454,7 +454,7 @@ func (s *stmt) ExecContext(ctx context.Context, args []sqldriver.NamedValue) (sq

func (s *stmt) Query(args []sqldriver.Value) (sqldriver.Rows, error) {
a := buildArgs(args)
r, err := s.Stmt.Execute(a...)
r, err := s.Execute(a...)
if err != nil {
return nil, s.connectionState.replyError(err)
}
Expand All @@ -465,7 +465,7 @@ func (s *stmt) QueryContext(ctx context.Context, args []sqldriver.NamedValue) (s
defer s.watchCtx(ctx)()

a := buildNamedArgs(args)
r, err := s.Stmt.Execute(a...)
r, err := s.Execute(a...)
if err != nil {
return nil, s.connectionState.replyError(err)
}
Expand All @@ -489,11 +489,11 @@ type result struct {
}

func (r *result) LastInsertId() (int64, error) {
return int64(r.Result.InsertId), nil
return int64(r.InsertId), nil
}

func (r *result) RowsAffected() (int64, error) {
return int64(r.Result.AffectedRows), nil
return int64(r.AffectedRows), nil
}

type rows struct {
Expand Down Expand Up @@ -531,14 +531,14 @@ func (r *rows) Close() error {
}

func (r *rows) Next(dest []sqldriver.Value) error {
if r.step >= r.Resultset.RowNumber() {
if r.step >= r.RowNumber() {
return io.EOF
} else if r.step == -1 {
return io.ErrUnexpectedEOF
}

for i := 0; i < r.Resultset.ColumnNumber(); i++ {
value, err := r.Resultset.GetValue(r.step, i)
for i := 0; i < r.ColumnNumber(); i++ {
value, err := r.GetValue(r.step, i)
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion dump/dumper.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ func (d *Dumper) Dump(w io.Writer) error {
// If we only dump some tables, the dump data will not have database name
// which makes us hard to parse, so here we add it manually.

_, err := w.Write([]byte(fmt.Sprintf("USE `%s`;\n", d.TableDB)))
_, err := fmt.Fprintf(w, "USE `%s`;\n", d.TableDB)
if err != nil {
return fmt.Errorf(`could not write USE command: %w`, err)
}
Expand Down
4 changes: 2 additions & 2 deletions mysql/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type Executer interface {

func (r *Result) Close() {
if r.Resultset != nil {
r.Resultset.returnToPool()
r.returnToPool()
r.Resultset = nil
}
}
Expand All @@ -39,7 +39,7 @@ func (r *Result) HasResultset() bool {
if r == nil {
return false
}
if r.Resultset != nil && len(r.Resultset.Fields) > 0 {
if r.Resultset != nil && len(r.Fields) > 0 {
return true
}
return false
Expand Down
5 changes: 3 additions & 2 deletions replication/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,14 +146,15 @@ func (h *BackupEventHandler) HandleEvent(e *BinlogEvent) error {
var err error
offset := e.Header.LogPos

if e.Header.EventType == ROTATE_EVENT {
switch e.Header.EventType {
case ROTATE_EVENT:
rotateEvent := e.Event.(*RotateEvent)
h.filename = string(rotateEvent.NextLogName)
if e.Header.Timestamp == 0 || offset == 0 {
// fake rotate event
return nil
}
} else if e.Header.EventType == FORMAT_DESCRIPTION_EVENT {
case FORMAT_DESCRIPTION_EVENT:
if h.w != nil {
if err = h.w.Close(); err != nil {
h.w = nil
Expand Down
2 changes: 1 addition & 1 deletion replication/binlogsyncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ func (b *BinlogSyncer) prepareSyncGTID(gset mysql.GTIDSet) error {
func (b *BinlogSyncer) onStream(s *BinlogStreamer) {
defer func() {
if e := recover(); e != nil {
s.closeWithError(fmt.Errorf("Err: %v\n Stack: %s", e, mysql.Pstack()))
s.closeWithError(fmt.Errorf("panic %v\nstack: %s", e, mysql.Pstack()))
}
b.wg.Done()
}()
Expand Down
6 changes: 1 addition & 5 deletions replication/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,7 @@ func (p *BinlogParser) parseSingleEvent(r io.Reader, onEvent OnEventFunc) (bool,
}

func (p *BinlogParser) ParseReader(r io.Reader, onEvent OnEventFunc) error {
for {
if atomic.LoadUint32(&p.stopProcessing) == 1 {
break
}

for atomic.LoadUint32(&p.stopProcessing) != 1 {
done, err := p.parseSingleEvent(r, onEvent)
if err != nil {
if err == errMissingTableMapEvent {
Expand Down
4 changes: 2 additions & 2 deletions replication/row_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -1060,7 +1060,7 @@ func (e *RowsEvent) decodeExtraData(data []byte) (err2 error) {
pos += 1
switch extraDataType {
case ENUM_EXTRA_ROW_INFO_TYPECODE_NDB:
var ndbLength int = int(data[pos])
ndbLength := int(data[pos])
pos += 1
e.NdbFormat = data[pos]
pos += 1
Expand Down Expand Up @@ -1388,7 +1388,7 @@ func (e *RowsEvent) decodeValue(data []byte, tp byte, meta uint16, isPartial boo
v = int64(binary.LittleEndian.Uint16(data))
n = 2
default:
err = fmt.Errorf("Unknown ENUM packlen=%d", l)
err = fmt.Errorf("unknown ENUM packlen=%d", l)
}
case mysql.MYSQL_TYPE_SET:
n = int(meta & 0xFF)
Expand Down
Loading
Loading