Skip to content
Open
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
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ jobs:
with:
go-version: "1.25.x"
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
uses: golangci/golangci-lint-action@v9
with:
version: v1.64.8
version: v2.6.2

test:
runs-on: ubuntu-latest
Expand Down
47 changes: 27 additions & 20 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,37 @@
run:
# timeout for analysis, e.g. 30s, 5m, default is 1m
timeout: 5m
version: "2"
linters:
enable:
#- golint
#- interfacer
- unconvert
#- dupl
- goconst
- gofmt
- misspell
- unparam
- nakedret
- prealloc
- revive
#- gosec
linters-settings:
misspell:
locale: US
revive:
- unconvert
- unparam
settings:
misspell:
locale: US
revive:
rules:
- name: redundant-build-tag
exclusions:
generated: lax
rules:
- name: redundant-build-tag
- path: (.+)\.go$
text: G104
paths:
- third_party$
- builtin$
- examples$
issues:
max-same-issues: 0
max-issues-per-linter: 0
exclude-use-default: false
exclude:
# gosec: Duplicated errcheck checks
- G104
max-same-issues: 0
formatters:
enable:
- gofmt
exclusions:
generated: lax
paths:
- third_party$
- builtin$
- examples$
2 changes: 1 addition & 1 deletion database/cassandra/cassandra.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ func parseConsistency(consistencyStr string) (consistency gocql.Consistency, err
var ok bool
err, ok = r.(error)
if !ok {
err = fmt.Errorf("Failed to parse consistency \"%s\": %v", consistencyStr, r)
err = fmt.Errorf("failed to parse consistency \"%s\": %v", consistencyStr, r)
}
}
}()
Expand Down
2 changes: 1 addition & 1 deletion database/clickhouse/clickhouse.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,5 +307,5 @@ func quoteIdentifier(name string) string {
if end > -1 {
name = name[:end]
}
return `"` + strings.Replace(name, `"`, `""`, -1) + `"`
return `"` + strings.ReplaceAll(name, `"`, `""`) + `"`
}
2 changes: 1 addition & 1 deletion database/mysql/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ var (
ErrNilConfig = fmt.Errorf("no config")
ErrNoDatabaseName = fmt.Errorf("no database name")
ErrAppendPEM = fmt.Errorf("failed to append PEM")
ErrTLSCertKeyConfig = fmt.Errorf("To use TLS client authentication, both x-tls-cert and x-tls-key must not be empty")
ErrTLSCertKeyConfig = fmt.Errorf("to use TLS client authentication, both x-tls-cert and x-tls-key must not be empty")
)

type Config struct {
Expand Down
8 changes: 4 additions & 4 deletions database/pgx/pgx.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func (p *Postgres) Open(url string) (database.Driver, error) {
if s := purl.Query().Get("x-migrations-table-quoted"); len(s) > 0 {
migrationsTableQuoted, err = strconv.ParseBool(s)
if err != nil {
return nil, fmt.Errorf("Unable to parse option x-migrations-table-quoted: %w", err)
return nil, fmt.Errorf("unable to parse option x-migrations-table-quoted: %w", err)
}
}
if (len(migrationsTable) > 0) && (migrationsTableQuoted) && ((migrationsTable[0] != '"') || (migrationsTable[len(migrationsTable)-1] != '"')) {
Expand Down Expand Up @@ -212,7 +212,7 @@ func (p *Postgres) Open(url string) (database.Driver, error) {
if s := purl.Query().Get("x-multi-statement"); len(s) > 0 {
multiStatementEnabled, err = strconv.ParseBool(s)
if err != nil {
return nil, fmt.Errorf("Unable to parse option x-multi-statement: %w", err)
return nil, fmt.Errorf("unable to parse option x-multi-statement: %w", err)
}
}

Expand Down Expand Up @@ -412,7 +412,7 @@ func (p *Postgres) runStatement(statement []byte) error {

func computeLineFromPos(s string, pos int) (line uint, col uint, ok bool) {
// replace crlf with lf
s = strings.Replace(s, "\r\n", "\n", -1)
s = strings.ReplaceAll(s, "\r\n", "\n")
// pg docs: pos uses index 1 for the first character, and positions are measured in characters not bytes
runes := []rune(s)
if pos > len(runes) {
Expand Down Expand Up @@ -613,5 +613,5 @@ func quoteIdentifier(name string) string {
if end > -1 {
name = name[:end]
}
return `"` + strings.Replace(name, `"`, `""`, -1) + `"`
return `"` + strings.ReplaceAll(name, `"`, `""`) + `"`
}
4 changes: 2 additions & 2 deletions database/pgx/pgx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -755,10 +755,10 @@ func Test_computeLineFromPos(t *testing.T) {
t.Run(name, func(t *testing.T) {
input := tc.input
if crlf {
input = strings.Replace(input, "\n", "\r\n", -1)
input = strings.ReplaceAll(input, "\n", "\r\n")
}
if nonASCII {
input = strings.Replace(input, "FROM", "FRÖM", -1)
input = strings.ReplaceAll(input, "FROM", "FRÖM")
}
gotLine, gotCol, gotOK := computeLineFromPos(input, tc.pos)

Expand Down
8 changes: 4 additions & 4 deletions database/pgx/v5/pgx.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func (p *Postgres) Open(url string) (database.Driver, error) {
if s := purl.Query().Get("x-migrations-table-quoted"); len(s) > 0 {
migrationsTableQuoted, err = strconv.ParseBool(s)
if err != nil {
return nil, fmt.Errorf("Unable to parse option x-migrations-table-quoted: %w", err)
return nil, fmt.Errorf("unable to parse option x-migrations-table-quoted: %w", err)
}
}
if (len(migrationsTable) > 0) && (migrationsTableQuoted) && ((migrationsTable[0] != '"') || (migrationsTable[len(migrationsTable)-1] != '"')) {
Expand Down Expand Up @@ -188,7 +188,7 @@ func (p *Postgres) Open(url string) (database.Driver, error) {
if s := purl.Query().Get("x-multi-statement"); len(s) > 0 {
multiStatementEnabled, err = strconv.ParseBool(s)
if err != nil {
return nil, fmt.Errorf("Unable to parse option x-multi-statement: %w", err)
return nil, fmt.Errorf("unable to parse option x-multi-statement: %w", err)
}
}

Expand Down Expand Up @@ -303,7 +303,7 @@ func (p *Postgres) runStatement(statement []byte) error {

func computeLineFromPos(s string, pos int) (line uint, col uint, ok bool) {
// replace crlf with lf
s = strings.Replace(s, "\r\n", "\n", -1)
s = strings.ReplaceAll(s, "\r\n", "\n")
// pg docs: pos uses index 1 for the first character, and positions are measured in characters not bytes
runes := []rune(s)
if pos > len(runes) {
Expand Down Expand Up @@ -476,5 +476,5 @@ func quoteIdentifier(name string) string {
if end > -1 {
name = name[:end]
}
return `"` + strings.Replace(name, `"`, `""`, -1) + `"`
return `"` + strings.ReplaceAll(name, `"`, `""`) + `"`
}
4 changes: 2 additions & 2 deletions database/pgx/v5/pgx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -730,10 +730,10 @@ func Test_computeLineFromPos(t *testing.T) {
t.Run(name, func(t *testing.T) {
input := tc.input
if crlf {
input = strings.Replace(input, "\n", "\r\n", -1)
input = strings.ReplaceAll(input, "\n", "\r\n")
}
if nonASCII {
input = strings.Replace(input, "FROM", "FRÖM", -1)
input = strings.ReplaceAll(input, "FROM", "FRÖM")
}
gotLine, gotCol, gotOK := computeLineFromPos(input, tc.pos)

Expand Down
6 changes: 3 additions & 3 deletions database/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func (p *Postgres) Open(url string) (database.Driver, error) {
if s := purl.Query().Get("x-migrations-table-quoted"); len(s) > 0 {
migrationsTableQuoted, err = strconv.ParseBool(s)
if err != nil {
return nil, fmt.Errorf("Unable to parse option x-migrations-table-quoted: %w", err)
return nil, fmt.Errorf("unable to parse option x-migrations-table-quoted: %w", err)
}
}
if (len(migrationsTable) > 0) && (migrationsTableQuoted) && ((migrationsTable[0] != '"') || (migrationsTable[len(migrationsTable)-1] != '"')) {
Expand Down Expand Up @@ -196,7 +196,7 @@ func (p *Postgres) Open(url string) (database.Driver, error) {
if s := purl.Query().Get("x-multi-statement"); len(s) > 0 {
multiStatementEnabled, err = strconv.ParseBool(s)
if err != nil {
return nil, fmt.Errorf("Unable to parse option x-multi-statement: %w", err)
return nil, fmt.Errorf("unable to parse option x-multi-statement: %w", err)
}
}

Expand Down Expand Up @@ -319,7 +319,7 @@ func (p *Postgres) runStatement(statement []byte) error {

func computeLineFromPos(s string, pos int) (line uint, col uint, ok bool) {
// replace crlf with lf
s = strings.Replace(s, "\r\n", "\n", -1)
s = strings.ReplaceAll(s, "\r\n", "\n")
// pg docs: pos uses index 1 for the first character, and positions are measured in characters not bytes
runes := []rune(s)
if pos > len(runes) {
Expand Down
4 changes: 2 additions & 2 deletions database/postgres/postgres_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -798,10 +798,10 @@ func Test_computeLineFromPos(t *testing.T) {
t.Run(name, func(t *testing.T) {
input := tc.input
if crlf {
input = strings.Replace(input, "\n", "\r\n", -1)
input = strings.ReplaceAll(input, "\n", "\r\n")
}
if nonASCII {
input = strings.Replace(input, "FROM", "FRÖM", -1)
input = strings.ReplaceAll(input, "FROM", "FRÖM")
}
gotLine, gotCol, gotOK := computeLineFromPos(input, tc.pos)

Expand Down
2 changes: 1 addition & 1 deletion database/redshift/redshift.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func (p *Redshift) Run(migration io.Reader) error {

func computeLineFromPos(s string, pos int) (line uint, col uint, ok bool) {
// replace crlf with lf
s = strings.Replace(s, "\r\n", "\n", -1)
s = strings.ReplaceAll(s, "\r\n", "\n")
// pg docs: pos uses index 1 for the first character, and positions are measured in characters not bytes
runes := []rune(s)
if pos > len(runes) {
Expand Down
4 changes: 2 additions & 2 deletions database/redshift/redshift_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,10 +378,10 @@ func Test_computeLineFromPos(t *testing.T) {
t.Run(name, func(t *testing.T) {
input := tc.input
if crlf {
input = strings.Replace(input, "\n", "\r\n", -1)
input = strings.ReplaceAll(input, "\n", "\r\n")
}
if nonASCII {
input = strings.Replace(input, "FROM", "FRÖM", -1)
input = strings.ReplaceAll(input, "FROM", "FRÖM")
}
gotLine, gotCol, gotOK := computeLineFromPos(input, tc.pos)

Expand Down
2 changes: 1 addition & 1 deletion database/snowflake/snowflake.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func (p *Snowflake) Run(migration io.Reader) error {

func computeLineFromPos(s string, pos int) (line uint, col uint, ok bool) {
// replace crlf with lf
s = strings.Replace(s, "\r\n", "\n", -1)
s = strings.ReplaceAll(s, "\r\n", "\n")
// pg docs: pos uses index 1 for the first character, and positions are measured in characters not bytes
runes := []rune(s)
if pos > len(runes) {
Expand Down
2 changes: 1 addition & 1 deletion database/sqlserver/sqlserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var (
ErrNoDatabaseName = fmt.Errorf("no database name")
ErrNoSchema = fmt.Errorf("no schema")
ErrDatabaseDirty = fmt.Errorf("database is dirty")
ErrMultipleAuthOptionsPassed = fmt.Errorf("both password and useMsi=true were passed.")
ErrMultipleAuthOptionsPassed = fmt.Errorf("both password and useMsi=true were passed")
)

var lockErrorMap = map[int]string{
Expand Down
2 changes: 1 addition & 1 deletion database/testing/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func TestLockAndUnlock(t *testing.T, d database.Driver) {
case <-done:
return
case <-timeout:
errs <- fmt.Errorf("Timeout after 15 seconds. Looks like a deadlock in Lock/UnLock.\n%#v", d)
errs <- fmt.Errorf("timeout after 15 seconds, looks like a deadlock in Lock/UnLock\n%#v", d)
return
}
}
Expand Down
10 changes: 5 additions & 5 deletions internal/cli/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import (
)

var (
errInvalidSequenceWidth = errors.New("Digits must be positive")
errIncompatibleSeqAndFormat = errors.New("The seq and format options are mutually exclusive")
errInvalidTimeFormat = errors.New("Time format may not be empty")
errInvalidSequenceWidth = errors.New("digits must be positive")
errIncompatibleSeqAndFormat = errors.New("the seq and format options are mutually exclusive")
errInvalidTimeFormat = errors.New("time format may not be empty")
)

func nextSeqVersion(matches []string, seqDigits int) (string, error) {
Expand All @@ -33,7 +33,7 @@ func nextSeqVersion(matches []string, seqDigits int) (string, error) {
idx := strings.Index(matchSeqStr, "_")

if idx < 1 { // Using 1 instead of 0 since there should be at least 1 digit
return "", fmt.Errorf("Malformed migration filename: %s", filename)
return "", fmt.Errorf("malformed migration filename: %s", filename)
}

var err error
Expand All @@ -50,7 +50,7 @@ func nextSeqVersion(matches []string, seqDigits int) (string, error) {
version := fmt.Sprintf("%0[2]*[1]d", nextSeq, seqDigits)

if len(version) > seqDigits {
return "", fmt.Errorf("Next sequence number %s too large. At most %d digits are allowed", version, seqDigits)
return "", fmt.Errorf("next sequence number %s too large, at most %d digits are allowed", version, seqDigits)
}

return version, nil
Expand Down
12 changes: 6 additions & 6 deletions internal/cli/commands_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,17 @@ func (s *CreateCmdSuite) TestNextSeqVersion() {
}{
{"Bad digits", []string{}, 0, "", errInvalidSequenceWidth},
{"Single digit initialize", []string{}, 1, "1", nil},
{"Single digit malformed", []string{"bad"}, 1, "", errors.New("Malformed migration filename: bad")},
{"Single digit malformed", []string{"bad"}, 1, "", errors.New("malformed migration filename: bad")},
{"Single digit no int", []string{"bad_bad"}, 1, "", errors.New(`strconv.ParseUint: parsing "bad": invalid syntax`)},
{"Single digit negative seq", []string{"-5_test"}, 1, "", errors.New(`strconv.ParseUint: parsing "-5": invalid syntax`)},
{"Single digit increment", []string{"3_test", "4_test"}, 1, "5", nil},
{"Single digit overflow", []string{"9_test"}, 1, "", errors.New("Next sequence number 10 too large. At most 1 digits are allowed")},
{"Single digit overflow", []string{"9_test"}, 1, "", errors.New("next sequence number 10 too large, at most 1 digits are allowed")},
{"Zero-pad initialize", []string{}, 6, "000001", nil},
{"Zero-pad malformed", []string{"bad"}, 6, "", errors.New("Malformed migration filename: bad")},
{"Zero-pad malformed", []string{"bad"}, 6, "", errors.New("malformed migration filename: bad")},
{"Zero-pad no int", []string{"bad_bad"}, 6, "", errors.New(`strconv.ParseUint: parsing "bad": invalid syntax`)},
{"Zero-pad negative seq", []string{"-000005_test"}, 6, "", errors.New(`strconv.ParseUint: parsing "-000005": invalid syntax`)},
{"Zero-pad increment", []string{"000003_test", "000004_test"}, 6, "000005", nil},
{"Zero-pad overflow", []string{"999999_test"}, 6, "", errors.New("Next sequence number 1000000 too large. At most 6 digits are allowed")},
{"Zero-pad overflow", []string{"999999_test"}, 6, "", errors.New("next sequence number 1000000 too large, at most 6 digits are allowed")},
{"dir absolute path", []string{"/migrationDir/000001_test"}, 6, "000002", nil},
{"dir relative path", []string{"migrationDir/000001_test"}, 6, "000002", nil},
{"dir dot prefix", []string{"./migrationDir/000001_test"}, 6, "000002", nil},
Expand Down Expand Up @@ -188,11 +188,11 @@ func (s *CreateCmdSuite) TestCreateCmd() {
{"seq init dir double dot relative trailing slash", []string{"subdir"}, "subdir", nil, []string{"subdir/0001_name.up.sql", "subdir/0001_name.down.sql"}, nil, "../subdir/", ts, defaultTimeFormat, true, 4, "sql", "name"},
{"seq init dir maze", []string{"subdir"}, "subdir", nil, []string{"0001_name.up.sql", "0001_name.down.sql"}, nil, "..//subdir/./.././/subdir/..", ts, defaultTimeFormat, true, 4, "sql", "name"},
{"seq width invalid", nil, "", nil, nil, errInvalidSequenceWidth, ".", ts, defaultTimeFormat, true, 0, "sql", "name"},
{"seq malformed", nil, "", []string{"bad.sql"}, []string{"bad.sql"}, errors.New("Malformed migration filename: bad.sql"), ".", ts, defaultTimeFormat, true, 4, "sql", "name"},
{"seq malformed", nil, "", []string{"bad.sql"}, []string{"bad.sql"}, errors.New("malformed migration filename: bad.sql"), ".", ts, defaultTimeFormat, true, 4, "sql", "name"},
{"seq not int", nil, "", []string{"bad_bad.sql"}, []string{"bad_bad.sql"}, errors.New(`strconv.ParseUint: parsing "bad": invalid syntax`), ".", ts, defaultTimeFormat, true, 4, "sql", "name"},
{"seq negative", nil, "", []string{"-5_negative.sql"}, []string{"-5_negative.sql"}, errors.New(`strconv.ParseUint: parsing "-5": invalid syntax`), ".", ts, defaultTimeFormat, true, 4, "sql", "name"},
{"seq increment", nil, "", []string{"3_three.sql", "4_four.sql"}, []string{"3_three.sql", "4_four.sql", "0005_five.up.sql", "0005_five.down.sql"}, nil, ".", ts, defaultTimeFormat, true, 4, "sql", "five"},
{"seq overflow", nil, "", []string{"9_nine.sql"}, []string{"9_nine.sql"}, errors.New(`Next sequence number 10 too large. At most 1 digits are allowed`), ".", ts, defaultTimeFormat, true, 1, "sql", "ten"},
{"seq overflow", nil, "", []string{"9_nine.sql"}, []string{"9_nine.sql"}, errors.New(`next sequence number 10 too large, at most 1 digits are allowed`), ".", ts, defaultTimeFormat, true, 1, "sql", "ten"},
{"time empty format", nil, "", nil, nil, errInvalidTimeFormat, ".", ts, "", false, 0, "sql", "name"},
{"time unix", nil, "", nil, []string{tsUnixStr + "_name.up.sql", tsUnixStr + "_name.down.sql"}, nil, ".", ts, "unix", false, 0, "sql", "name"},
{"time unixNano", nil, "", nil, []string{tsUnixNanoStr + "_name.up.sql", tsUnixNanoStr + "_name.down.sql"}, nil, ".", ts, "unixNano", false, 0, "sql", "name"},
Expand Down
2 changes: 1 addition & 1 deletion source/gitlab/gitlab.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ func (g *Gitlab) readDirectory() error {
if response.CurrentPage >= response.TotalPages {
break
}
g.listOptions.ListOptions.Page = response.NextPage
g.listOptions.Page = response.NextPage
}

for i := range nodes {
Expand Down
2 changes: 1 addition & 1 deletion source/httpfs/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ func New(fs http.FileSystem, path string) (source.Driver, error) {
// Open completes the implementetion of source.Driver interface. Other methods
// are implemented by the embedded PartialDriver struct.
func (d *driver) Open(url string) (source.Driver, error) {
return nil, errors.New("Open() cannot be called on the httpfs passthrough driver")
return nil, errors.New("open() cannot be called on the httpfs passthrough driver")
}
2 changes: 1 addition & 1 deletion source/iofs/iofs.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func New(fsys fs.FS, path string) (source.Driver, error) {
// Open is part of source.Driver interface implementation.
// Open cannot be called on the iofs passthrough driver.
func (d *driver) Open(url string) (source.Driver, error) {
return nil, errors.New("Open() cannot be called on the iofs passthrough driver")
return nil, errors.New("open() cannot be called on the iofs passthrough driver")
}

// PartialDriver is a helper service for creating new source drivers working with
Expand Down
Loading