Skip to content

Commit 35fb337

Browse files
zyv4ykrubenv
authored andcommitted
updated golanglint ci version
1 parent 67a517e commit 35fb337

File tree

5 files changed

+135
-118
lines changed

5 files changed

+135
-118
lines changed

.github/workflows/test.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ jobs:
3636
cache: true
3737
cache-dependency-path: go.sum
3838
- name: golangci-lint
39-
uses: golangci/golangci-lint-action@v6
39+
uses: golangci/golangci-lint-action@v7
4040
with:
41-
version: v1.64
41+
version: v2
4242
- name: go mod tidy
4343
run: go mod tidy
4444
- name: check for any changes

.golangci.yaml

Lines changed: 115 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -1,117 +1,133 @@
1-
linters-settings:
2-
gocritic:
3-
disabled-checks:
4-
- ifElseChain
5-
6-
goimports:
7-
local-prefixes: github.com/rubenv/sql-migrate
8-
9-
govet:
10-
enable-all: true
11-
disable:
12-
- fieldalignment
13-
14-
depguard:
15-
rules:
16-
main:
17-
allow:
18-
- $gostd
19-
- github.com/denisenkom/go-mssqldb
20-
- github.com/go-sql-driver/mysql
21-
- github.com/go-gorp/gorp/v3
22-
- github.com/lib/pq
23-
- github.com/mattn/go-sqlite3
24-
- github.com/mitchellh/cli
25-
- github.com/olekukonko/tablewriter
26-
- github.com/rubenv/sql-migrate
27-
- gopkg.in/check.v1
28-
- gopkg.in/yaml.v2
29-
30-
exhaustive:
31-
default-signifies-exhaustive: true
32-
33-
nolintlint:
34-
allow-unused: false
35-
allow-no-explanation:
36-
- depguard
37-
require-explanation: true
38-
require-specific: true
39-
40-
revive:
41-
enable-all-rules: false
42-
rules:
43-
- name: atomic
44-
- name: blank-imports
45-
- name: bool-literal-in-expr
46-
- name: call-to-gc
47-
- name: constant-logical-expr
48-
- name: context-as-argument
49-
- name: context-keys-type
50-
- name: dot-imports
51-
- name: duplicated-imports
52-
- name: empty-block
53-
- name: empty-lines
54-
- name: error-naming
55-
- name: error-return
56-
- name: error-strings
57-
- name: errorf
58-
- name: exported
59-
- name: identical-branches
60-
- name: imports-blocklist
61-
- name: increment-decrement
62-
- name: indent-error-flow
63-
- name: modifies-parameter
64-
- name: modifies-value-receiver
65-
- name: package-comments
66-
- name: range
67-
- name: range-val-address
68-
- name: range-val-in-closure
69-
- name: receiver-naming
70-
- name: string-format
71-
- name: string-of-int
72-
- name: struct-tag
73-
- name: time-naming
74-
- name: unconditional-recursion
75-
- name: unexported-naming
76-
- name: unexported-return
77-
- name: superfluous-else
78-
- name: unreachable-code
79-
- name: var-declaration
80-
- name: waitgroup-by-value
81-
- name: unused-receiver
82-
- name: unnecessary-stmt
83-
- name: unused-parameter
84-
1+
version: "2"
852
run:
863
tests: true
87-
timeout: 1m
88-
894
linters:
90-
disable-all: true
5+
default: none
916
enable:
927
- asciicheck
938
- depguard
949
- errcheck
10+
- errorlint
9511
- exhaustive
9612
- gocritic
97-
- gofmt
98-
- gofumpt
99-
- goimports
10013
- govet
10114
- ineffassign
10215
- nolintlint
10316
- revive
10417
- staticcheck
105-
- typecheck
18+
- unparam
10619
- unused
10720
- whitespace
108-
- errorlint
109-
- gosimple
110-
- unparam
111-
21+
settings:
22+
depguard:
23+
rules:
24+
main:
25+
allow:
26+
- $gostd
27+
- github.com/denisenkom/go-mssqldb
28+
- github.com/go-sql-driver/mysql
29+
- github.com/go-gorp/gorp/v3
30+
- github.com/lib/pq
31+
- github.com/mattn/go-sqlite3
32+
- github.com/mitchellh/cli
33+
- github.com/olekukonko/tablewriter
34+
- github.com/rubenv/sql-migrate
35+
- gopkg.in/check.v1
36+
- gopkg.in/yaml.v2
37+
exhaustive:
38+
default-signifies-exhaustive: true
39+
gocritic:
40+
disabled-checks:
41+
- ifElseChain
42+
govet:
43+
disable:
44+
- fieldalignment
45+
enable-all: true
46+
nolintlint:
47+
require-explanation: true
48+
require-specific: true
49+
allow-no-explanation:
50+
- depguard
51+
allow-unused: false
52+
revive:
53+
enable-all-rules: false
54+
rules:
55+
- name: atomic
56+
- name: blank-imports
57+
- name: bool-literal-in-expr
58+
- name: call-to-gc
59+
- name: constant-logical-expr
60+
- name: context-as-argument
61+
- name: context-keys-type
62+
- name: dot-imports
63+
- name: duplicated-imports
64+
- name: empty-block
65+
- name: empty-lines
66+
- name: error-naming
67+
- name: error-return
68+
- name: error-strings
69+
- name: errorf
70+
- name: exported
71+
- name: identical-branches
72+
- name: imports-blocklist
73+
- name: increment-decrement
74+
- name: indent-error-flow
75+
- name: modifies-parameter
76+
- name: modifies-value-receiver
77+
- name: package-comments
78+
- name: range
79+
- name: range-val-address
80+
- name: range-val-in-closure
81+
- name: receiver-naming
82+
- name: string-format
83+
- name: string-of-int
84+
- name: struct-tag
85+
- name: time-naming
86+
- name: unconditional-recursion
87+
- name: unexported-naming
88+
- name: unexported-return
89+
- name: superfluous-else
90+
- name: unreachable-code
91+
- name: var-declaration
92+
- name: waitgroup-by-value
93+
- name: unused-receiver
94+
- name: unnecessary-stmt
95+
- name: unused-parameter
96+
exclusions:
97+
generated: lax
98+
presets:
99+
- comments
100+
- common-false-positives
101+
- legacy
102+
- std-error-handling
103+
rules:
104+
- path: (.+)\.go$
105+
text: declaration of "err" shadows declaration at
106+
- path: (.+)\.go$
107+
text: 'error-strings: error strings should not be capitalized or end with punctuation or a newline'
108+
- path: (.+)\.go$
109+
text: 'ST1005: error strings should not end with punctuation or newline'
110+
- path: (.+)\.go$
111+
text: 'ST1005: error strings should not be capitalized'
112+
paths:
113+
- third_party$
114+
- builtin$
115+
- examples$
112116
issues:
113-
exclude:
114-
- 'declaration of "err" shadows declaration at' # Allow shadowing of `err` because it's so common
115-
- 'error-strings: error strings should not be capitalized or end with punctuation or a newline'
116-
max-same-issues: 10000
117117
max-issues-per-linter: 10000
118+
max-same-issues: 10000
119+
formatters:
120+
enable:
121+
- gofmt
122+
- gofumpt
123+
- goimports
124+
settings:
125+
goimports:
126+
local-prefixes:
127+
- github.com/rubenv/sql-migrate
128+
exclusions:
129+
generated: lax
130+
paths:
131+
- third_party$
132+
- builtin$
133+
- examples$

migrate.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -700,13 +700,14 @@ func (ms MigrationSet) planMigrationCommon(db *sql.DB, dialect string, m Migrati
700700
toApplyCount = max
701701
}
702702
for _, v := range toApply[0:toApplyCount] {
703-
if dir == Up {
703+
switch dir {
704+
case Up:
704705
result = append(result, &PlannedMigration{
705706
Migration: v,
706707
Queries: v.Up,
707708
DisableTransaction: v.DisableTransactionUp,
708709
})
709-
} else if dir == Down {
710+
case Down:
710711
result = append(result, &PlannedMigration{
711712
Migration: v,
712713
Queries: v.Down,
@@ -779,14 +780,13 @@ func ToApply(migrations []*Migration, current string, direction MigrationDirecti
779780
}
780781
}
781782

782-
if direction == Up {
783+
switch direction {
784+
case Up:
783785
return migrations[index+1:]
784-
} else if direction == Down {
786+
case Down:
785787
if index == -1 {
786788
return []*Migration{}
787789
}
788-
789-
// Add in reverse order
790790
toApply := make([]*Migration, index+1)
791791
for i := 0; i < index+1; i++ {
792792
toApply[index-i] = migrations[i]

migrate_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -445,31 +445,31 @@ func (s *SqliteMigrateSuite) TestPlanMigrationWithHoles(c *C) {
445445
plannedMigrations, _, err := PlanMigration(s.Db, "sqlite3", migrations, Up, 0)
446446
c.Assert(err, IsNil)
447447
c.Assert(plannedMigrations, HasLen, 3)
448-
c.Assert(plannedMigrations[0].Migration.Id, Equals, "2")
448+
c.Assert(plannedMigrations[0].Id, Equals, "2")
449449
c.Assert(plannedMigrations[0].Queries[0], Equals, up)
450-
c.Assert(plannedMigrations[1].Migration.Id, Equals, "4")
450+
c.Assert(plannedMigrations[1].Id, Equals, "4")
451451
c.Assert(plannedMigrations[1].Queries[0], Equals, up)
452-
c.Assert(plannedMigrations[2].Migration.Id, Equals, "5")
452+
c.Assert(plannedMigrations[2].Id, Equals, "5")
453453
c.Assert(plannedMigrations[2].Queries[0], Equals, up)
454454

455455
// first catch up to current target state 123, then migrate down 1 step to 12
456456
plannedMigrations, _, err = PlanMigration(s.Db, "sqlite3", migrations, Down, 1)
457457
c.Assert(err, IsNil)
458458
c.Assert(plannedMigrations, HasLen, 2)
459-
c.Assert(plannedMigrations[0].Migration.Id, Equals, "2")
459+
c.Assert(plannedMigrations[0].Id, Equals, "2")
460460
c.Assert(plannedMigrations[0].Queries[0], Equals, up)
461-
c.Assert(plannedMigrations[1].Migration.Id, Equals, "3")
461+
c.Assert(plannedMigrations[1].Id, Equals, "3")
462462
c.Assert(plannedMigrations[1].Queries[0], Equals, down)
463463

464464
// first catch up to current target state 123, then migrate down 2 steps to 1
465465
plannedMigrations, _, err = PlanMigration(s.Db, "sqlite3", migrations, Down, 2)
466466
c.Assert(err, IsNil)
467467
c.Assert(plannedMigrations, HasLen, 3)
468-
c.Assert(plannedMigrations[0].Migration.Id, Equals, "2")
468+
c.Assert(plannedMigrations[0].Id, Equals, "2")
469469
c.Assert(plannedMigrations[0].Queries[0], Equals, up)
470-
c.Assert(plannedMigrations[1].Migration.Id, Equals, "3")
470+
c.Assert(plannedMigrations[1].Id, Equals, "3")
471471
c.Assert(plannedMigrations[1].Queries[0], Equals, down)
472-
c.Assert(plannedMigrations[2].Migration.Id, Equals, "2")
472+
c.Assert(plannedMigrations[2].Id, Equals, "2")
473473
c.Assert(plannedMigrations[2].Queries[0], Equals, down)
474474
}
475475

sql-migrate/command_common.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,18 @@ func ApplyMigrations(dir migrate.MigrationDirection, dryrun bool, limit int, ver
6262
}
6363

6464
func PrintMigration(m *migrate.PlannedMigration, dir migrate.MigrationDirection) {
65-
if dir == migrate.Up {
65+
switch dir {
66+
case migrate.Up:
6667
ui.Output(fmt.Sprintf("==> Would apply migration %s (up)", m.Id))
6768
for _, q := range m.Up {
6869
ui.Output(q)
6970
}
70-
} else if dir == migrate.Down {
71+
case migrate.Down:
7172
ui.Output(fmt.Sprintf("==> Would apply migration %s (down)", m.Id))
7273
for _, q := range m.Down {
7374
ui.Output(q)
7475
}
75-
} else {
76+
default:
7677
panic("Not reached")
7778
}
7879
}

0 commit comments

Comments
 (0)