Skip to content

Commit 167b0f4

Browse files
authored
chore(models): rewrite code format. (#14754)
* chore: rewrite format. * chore: update format Signed-off-by: Bo-Yi Wu <[email protected]> * chore: update format Signed-off-by: Bo-Yi Wu <[email protected]> * chore: Adjacent parameters with the same type should be grouped together * chore: update format.
1 parent 164e35e commit 167b0f4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+474
-460
lines changed

models/access.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ func (user *User) GetRepositoryAccesses() (map[*Repository]AccessMode, error) {
121121
}
122122
defer rows.Close()
123123

124-
var repos = make(map[*Repository]AccessMode, 10)
125-
var ownerCache = make(map[int64]*User, 10)
124+
repos := make(map[*Repository]AccessMode, 10)
125+
ownerCache := make(map[int64]*User, 10)
126126
for rows.Next() {
127127
var repo repoAccess
128128
err = rows.Scan(&repo)

models/action.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ func (a *Action) GetRepoLink() string {
186186
}
187187

188188
// GetRepositoryFromMatch returns a *Repository from a username and repo strings
189-
func GetRepositoryFromMatch(ownerName string, repoName string) (*Repository, error) {
189+
func GetRepositoryFromMatch(ownerName, repoName string) (*Repository, error) {
190190
var err error
191191
refRepo, err := GetRepositoryByOwnerAndName(ownerName, repoName)
192192
if err != nil {
@@ -218,7 +218,7 @@ func (a *Action) getCommentLink(e Engine) string {
218218
if len(a.GetIssueInfos()) == 0 {
219219
return "#"
220220
}
221-
//Return link to issue
221+
// Return link to issue
222222
issueIDString := a.GetIssueInfos()[0]
223223
issueID, err := strconv.ParseInt(issueIDString, 10, 64)
224224
if err != nil {
@@ -322,7 +322,7 @@ func GetFeeds(opts GetFeedsOptions) ([]*Action, error) {
322322
return actions, nil
323323
}
324324

325-
func activityReadable(user *User, doer *User) bool {
325+
func activityReadable(user, doer *User) bool {
326326
var doerID int64
327327
if doer != nil {
328328
doerID = doer.ID

models/admin.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ import (
1414
"code.gitea.io/gitea/modules/util"
1515
)
1616

17-
//NoticeType describes the notice type
17+
// NoticeType describes the notice type
1818
type NoticeType int
1919

2020
const (
21-
//NoticeRepository type
21+
// NoticeRepository type
2222
NoticeRepository NoticeType = iota + 1
2323
// NoticeTask type
2424
NoticeTask

models/attachment.go

+2-4
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ func DeleteAttachments(attachments []*Attachment, remove bool) (int, error) {
193193
return 0, nil
194194
}
195195

196-
var ids = make([]int64, 0, len(attachments))
196+
ids := make([]int64, 0, len(attachments))
197197
for _, a := range attachments {
198198
ids = append(ids, a.ID)
199199
}
@@ -216,7 +216,6 @@ func DeleteAttachments(attachments []*Attachment, remove bool) (int, error) {
216216
// DeleteAttachmentsByIssue deletes all attachments associated with the given issue.
217217
func DeleteAttachmentsByIssue(issueID int64, remove bool) (int, error) {
218218
attachments, err := GetAttachmentsByIssueID(issueID)
219-
220219
if err != nil {
221220
return 0, err
222221
}
@@ -227,7 +226,6 @@ func DeleteAttachmentsByIssue(issueID int64, remove bool) (int, error) {
227226
// DeleteAttachmentsByComment deletes all attachments associated with the given comment.
228227
func DeleteAttachmentsByComment(commentID int64, remove bool) (int, error) {
229228
attachments, err := GetAttachmentsByCommentID(commentID)
230-
231229
if err != nil {
232230
return 0, err
233231
}
@@ -263,7 +261,7 @@ func IterateAttachment(f func(attach *Attachment) error) error {
263261
var start int
264262
const batchSize = 100
265263
for {
266-
var attachments = make([]*Attachment, 0, batchSize)
264+
attachments := make([]*Attachment, 0, batchSize)
267265
if err := x.Limit(batchSize, start).Find(&attachments); err != nil {
268266
return err
269267
}

models/attachment_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ func TestUploadAttachment(t *testing.T) {
1717

1818
user := AssertExistsAndLoadBean(t, &User{ID: 1}).(*User)
1919

20-
var fPath = "./attachment_test.go"
20+
fPath := "./attachment_test.go"
2121
f, err := os.Open(fPath)
2222
assert.NoError(t, err)
2323
defer f.Close()
2424

25-
var buf = make([]byte, 1024)
25+
buf := make([]byte, 1024)
2626
n, err := f.Read(buf)
2727
assert.NoError(t, err)
2828
buf = buf[:n]
@@ -152,7 +152,6 @@ func TestLinkedRepository(t *testing.T) {
152152
assert.Equal(t, tc.expectedRepo.ID, repo.ID)
153153
}
154154
assert.Equal(t, tc.expectedUnitType, unitType)
155-
156155
})
157156
}
158157
}

models/commit_status.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,11 @@ func FindRepoRecentCommitStatusContexts(repoID int64, before time.Duration) ([]s
176176
return nil, err
177177
}
178178

179-
var contexts = make([]string, 0, len(ids))
179+
contexts := make([]string, 0, len(ids))
180180
if len(ids) == 0 {
181181
return contexts, nil
182182
}
183183
return contexts, x.Select("context").Table("commit_status").In("id", ids).Find(&contexts)
184-
185184
}
186185

187186
// NewCommitStatusOptions holds options for creating a CommitStatus

models/error.go

+3-6
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ func (err ErrNameCharsNotAllowed) Error() string {
7272
}
7373

7474
// ErrSSHDisabled represents an "SSH disabled" error.
75-
type ErrSSHDisabled struct {
76-
}
75+
type ErrSSHDisabled struct{}
7776

7877
// IsErrSSHDisabled checks if an error is a ErrSSHDisabled.
7978
func IsErrSSHDisabled(err error) bool {
@@ -269,8 +268,7 @@ func (err ErrUserHasOrgs) Error() string {
269268
}
270269

271270
// ErrUserNotAllowedCreateOrg represents a "UserNotAllowedCreateOrg" kind of error.
272-
type ErrUserNotAllowedCreateOrg struct {
273-
}
271+
type ErrUserNotAllowedCreateOrg struct{}
274272

275273
// IsErrUserNotAllowedCreateOrg checks if an error is an ErrUserNotAllowedCreateOrg.
276274
func IsErrUserNotAllowedCreateOrg(err error) bool {
@@ -603,8 +601,7 @@ func (err ErrAccessTokenNotExist) Error() string {
603601
}
604602

605603
// ErrAccessTokenEmpty represents a "AccessTokenEmpty" kind of error.
606-
type ErrAccessTokenEmpty struct {
607-
}
604+
type ErrAccessTokenEmpty struct{}
608605

609606
// IsErrAccessTokenEmpty checks if an error is a ErrAccessTokenEmpty.
610607
func IsErrAccessTokenEmpty(err error) bool {

models/external_login_user.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ func ListAccountLinks(user *User) ([]*ExternalLoginUser, error) {
4545
err := x.Where("user_id=?", user.ID).
4646
Desc("login_source_id").
4747
Find(&externalAccounts)
48-
4948
if err != nil {
5049
return nil, err
5150
}
@@ -87,7 +86,7 @@ func removeAllAccountLinks(e Engine, user *User) error {
8786
}
8887

8988
// GetUserIDByExternalUserID get user id according to provider and userID
90-
func GetUserIDByExternalUserID(provider string, userID string) (int64, error) {
89+
func GetUserIDByExternalUserID(provider, userID string) (int64, error) {
9190
var id int64
9291
_, err := x.Table("external_login_user").
9392
Select("user_id").
@@ -147,7 +146,7 @@ type FindExternalUserOptions struct {
147146
}
148147

149148
func (opts FindExternalUserOptions) toConds() builder.Cond {
150-
var cond = builder.NewCond()
149+
cond := builder.NewCond()
151150
if len(opts.Provider) > 0 {
152151
cond = cond.And(builder.Eq{"provider": opts.Provider})
153152
}

models/fixture_generation.go

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
// GetYamlFixturesAccess returns a string containing the contents
1313
// for the access table, as recalculated using repo.RecalculateAccesses()
1414
func GetYamlFixturesAccess() (string, error) {
15-
1615
repos := make([]*Repository, 0, 50)
1716
if err := x.Find(&repos); err != nil {
1817
return "", err

0 commit comments

Comments
 (0)