Skip to content

Commit

Permalink
style: upgrade linter
Browse files Browse the repository at this point in the history
  • Loading branch information
trim21 committed Oct 10, 2024
1 parent cc05cf2 commit 25fbccd
Show file tree
Hide file tree
Showing 13 changed files with 16 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ jobs:
- name: Run linters
uses: golangci/golangci-lint-action@v6
with:
version: v1.59.1
version: v1.61.0
24 changes: 9 additions & 15 deletions .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ run:
# If false (default) - golangci-lint acquires file lock on start.
allow-parallel-runners: true

skip-files: []

go: "1.22"
go: "1.23"

# output configuration options
output:
Expand Down Expand Up @@ -106,8 +104,6 @@ linters-settings:
- standard # Captures all standard packages if they do not match another section.
- default # Contains all imports that could not be matched to another section type.
- prefix(github.com/bangumi/server) # Groups all imports with the specified Prefix.
sectionSeparators:
- newLine

depguard:
rules:
Expand Down Expand Up @@ -141,8 +137,8 @@ linters-settings:
- operation
- return
- assign
ignored-functions: strconv\..*,time\..*,make,math\..*,strings\..*
ignored-numbers: 1,2,3,10,100,1000,10000
ignored-functions: [strconv\..*, time\..*, make, math\..*, strings\..*]
ignored-numbers: ["1", "2", "3", "10", "100", "1000", "10000"]

gosimple:
# Select the Go version to target. The default is '1.13'.
Expand Down Expand Up @@ -181,7 +177,7 @@ linters-settings:
checks: ["all"]

stylecheck:
# Select the Go version to target. The default is '1.13'.
# Select the Go version to target. The default is '1.13'.

testpackage:
# regexp pattern to skip files
Expand All @@ -203,12 +199,9 @@ linters-settings:
nlreturn:
block-size: 3

ifshort:
# Maximum length of vars declaration measured in number of lines, after which linter won't suggest using short syntax.
# Has higher priority than max-decl-chars.
max-decl-lines: 1
# Maximum length of vars declaration measured in number of characters, after which linter won't suggest using short syntax.
max-decl-chars: 30
gosec:
excludes:
- G115

tagliatelle:
# Check the struck tag name case.
Expand Down Expand Up @@ -236,8 +229,9 @@ linters:
- errchkjson
- errname
- errorlint
# https://github.com/golangci/golangci-lint/issues/5065
- exhaustive
- exportloopref
- copyloopvar
- forbidigo
- forcetypeassert
- funlen
Expand Down
4 changes: 2 additions & 2 deletions internal/collections/infra/mysql_repo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,12 @@ func TestMysqlRepo_ListSubjectCollection(t *testing.T) {
require.NoError(t, err)
}

for i := 0; i < 2; i++ {
for i := uint32(0); i < 2; i++ {
err = q.SubjectCollection.
WithContext(context.Background()).
Create(&dao.SubjectCollection{
UserID: uid,
SubjectID: model.SubjectID(200 + i),
SubjectID: 200 + i,
SubjectType: model.SubjectTypeGame,
UpdatedTime: uint32(time.Now().Unix()),
})
Expand Down
10 changes: 4 additions & 6 deletions internal/index/mysql_repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,8 @@ func TestMysqlRepo_DeleteIndex2(t *testing.T) {
err := repo.New(ctx, index)
require.NoError(t, err)

for i := 10; i < 20; i++ {
_, err = repo.AddOrUpdateIndexSubject(ctx, index.ID, model.SubjectID(i),
uint32(i), fmt.Sprintf("comment %d", i))
for i := uint32(10); i < 20; i++ {
_, err = repo.AddOrUpdateIndexSubject(ctx, index.ID, i, i, fmt.Sprintf("comment %d", i))
require.NoError(t, err)
}

Expand Down Expand Up @@ -292,9 +291,8 @@ func TestMysqlRepo_DeleteIndexSubject(t *testing.T) {
require.NotEqual(t, 0, index.ID)
require.NoError(t, err)

for i := 10; i < 20; i++ {
_, err = repo.AddOrUpdateIndexSubject(ctx, index.ID, model.SubjectID(i),
uint32(i), fmt.Sprintf("comment %d", i))
for i := uint32(10); i < 20; i++ {
_, err = repo.AddOrUpdateIndexSubject(ctx, index.ID, i, i, fmt.Sprintf("comment %d", i))
require.NoError(t, err)
}

Expand Down
1 change: 0 additions & 1 deletion internal/pkg/generic/set/set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ func TestFromSlice(t *testing.T) {
{"init without values", []string{}},
}
for _, tc := range testcases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()
s := set.FromSlice[string](tc.input)
Expand Down
1 change: 0 additions & 1 deletion pkg/duration/duration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ func TestParse(t *testing.T) {
}

for _, tc := range testcases {
tc := tc
t.Run(tc.Name, func(t *testing.T) {
t.Parallel()
actual, err := duration.Parse(tc.Input)
Expand Down
1 change: 0 additions & 1 deletion pkg/wiki/spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ func TestAgainstInvalidSpec(t *testing.T) {

for _, file := range files {
// name := file.Name()
file := file
t.Run(file.Name(), func(t *testing.T) {
t.Parallel()
raw, err := os.ReadFile(filepath.Join(caseRoot, file.Name()))
Expand Down
1 change: 0 additions & 1 deletion web/handler/character/character_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ func TestCharacter_GetImage(t *testing.T) {
app := test.GetWebApp(t, test.Mock{CharacterRepo: m})

for _, imageType := range []string{"large", "grid", "medium", "small"} {
imageType := imageType
t.Run(imageType, func(t *testing.T) {
t.Parallel()

Expand Down
1 change: 0 additions & 1 deletion web/handler/person/person_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ func TestPerson_GetImage(t *testing.T) {
app := test.GetWebApp(t, test.Mock{PersonRepo: m})

for _, imageType := range []string{"small", "grid", "large", "medium"} {
imageType := imageType
t.Run(imageType, func(t *testing.T) {
t.Parallel()

Expand Down
2 changes: 0 additions & 2 deletions web/handler/revision_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ func TestHandler_ListPersonRevision_Bad_ID(t *testing.T) {
badIDs := []string{"-1", "a", "0"}

for _, id := range badIDs {
id := id
t.Run(id, func(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -122,7 +121,6 @@ func TestHandler_ListSubjectRevision_Bad_ID(t *testing.T) {
badIDs := []string{"-1", "a", "0"}

for _, id := range badIDs {
id := id
t.Run(id, func(t *testing.T) {
t.Parallel()

Expand Down
2 changes: 0 additions & 2 deletions web/handler/subject/get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ func TestSubject_Get_bad_id(t *testing.T) {
app := test.GetWebApp(t, test.Mock{SubjectRepo: m})

for _, path := range []string{"/v0/subjects/0", "/v0/subjects/-1", "/v0/subjects/a"} {
path := path
t.Run(path, func(t *testing.T) {
t.Parallel()

Expand All @@ -154,7 +153,6 @@ func TestSubject_GetImage_302(t *testing.T) {
app := test.GetWebApp(t, test.Mock{SubjectRepo: m})

for _, imageType := range []string{"small", "grid", "large", "medium", "common"} {
imageType := imageType
t.Run(imageType, func(t *testing.T) {
t.Parallel()

Expand Down
1 change: 0 additions & 1 deletion web/handler/user/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ func TestUser_GetAvatar_302(t *testing.T) {

app := test.GetWebApp(t, test.Mock{UserRepo: m})
for _, imageType := range []string{"large", "medium", "small"} {
imageType := imageType
t.Run(imageType, func(t *testing.T) {
t.Parallel()

Expand Down
2 changes: 0 additions & 2 deletions web/req/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ func TestLoginPass(t *testing.T) {
}
validate := validator.New()
for i, login := range testCase {
login := login
t.Run(fmt.Sprintf("success %d", i), func(t *testing.T) {
t.Parallel()
require.NoError(t, validate.Struct(login))
Expand All @@ -50,7 +49,6 @@ func TestLoginErr(t *testing.T) {
}
validate := validator.New()
for i, login := range testCase {
login := login
t.Run(fmt.Sprintf("fail %d", i), func(t *testing.T) {
t.Parallel()
require.Error(t, validate.Struct(login))
Expand Down

0 comments on commit 25fbccd

Please sign in to comment.