Skip to content

Commit 9c4601b

Browse files
authored
Code Formats, Nits & Unused Func/Var deletions (#15286)
* _ to unused func options * rm useless brakets * rm trifial non used models functions * rm dead code * rm dead global vars * fix routers/api/v1/repo/issue.go * dont overload import module
1 parent 0991f9a commit 9c4601b

33 files changed

+41
-98
lines changed

cmd/admin.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ func runDeleteUser(c *cli.Context) error {
512512
return models.DeleteUser(user)
513513
}
514514

515-
func runRepoSyncReleases(c *cli.Context) error {
515+
func runRepoSyncReleases(_ *cli.Context) error {
516516
if err := initDB(); err != nil {
517517
return err
518518
}
@@ -578,14 +578,14 @@ func getReleaseCount(id int64) (int64, error) {
578578
)
579579
}
580580

581-
func runRegenerateHooks(c *cli.Context) error {
581+
func runRegenerateHooks(_ *cli.Context) error {
582582
if err := initDB(); err != nil {
583583
return err
584584
}
585585
return repo_module.SyncRepositoryHooks(graceful.GetManager().ShutdownContext())
586586
}
587587

588-
func runRegenerateKeys(c *cli.Context) error {
588+
func runRegenerateKeys(_ *cli.Context) error {
589589
if err := initDB(); err != nil {
590590
return err
591591
}

cmd/hook.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ Gitea or set your environment appropriately.`, "")
166166
}
167167

168168
// the environment setted on serv command
169-
isWiki := (os.Getenv(models.EnvRepoIsWiki) == "true")
169+
isWiki := os.Getenv(models.EnvRepoIsWiki) == "true"
170170
username := os.Getenv(models.EnvRepoUsername)
171171
reponame := os.Getenv(models.EnvRepoName)
172172
userID, _ := strconv.ParseInt(os.Getenv(models.EnvPusherID), 10, 64)
@@ -322,7 +322,7 @@ Gitea or set your environment appropriately.`, "")
322322

323323
// the environment setted on serv command
324324
repoUser := os.Getenv(models.EnvRepoUsername)
325-
isWiki := (os.Getenv(models.EnvRepoIsWiki) == "true")
325+
isWiki := os.Getenv(models.EnvRepoIsWiki) == "true"
326326
repoName := os.Getenv(models.EnvRepoName)
327327
pusherID, _ := strconv.ParseInt(os.Getenv(models.EnvPusherID), 10, 64)
328328
pusherName := os.Getenv(models.EnvPusherName)

models/branches.go

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -260,12 +260,6 @@ func (protectBranch *ProtectedBranch) IsProtectedFile(patterns []glob.Glob, path
260260
return r
261261
}
262262

263-
// GetProtectedBranchByRepoID getting protected branch by repo ID
264-
func GetProtectedBranchByRepoID(repoID int64) ([]*ProtectedBranch, error) {
265-
protectedBranches := make([]*ProtectedBranch, 0)
266-
return protectedBranches, x.Where("repo_id = ?", repoID).Desc("updated_unix").Find(&protectedBranches)
267-
}
268-
269263
// GetProtectedBranchBy getting protected branch by ID/Name
270264
func GetProtectedBranchBy(repoID int64, branchName string) (*ProtectedBranch, error) {
271265
return getProtectedBranchBy(x, repoID, branchName)
@@ -283,19 +277,6 @@ func getProtectedBranchBy(e Engine, repoID int64, branchName string) (*Protected
283277
return rel, nil
284278
}
285279

286-
// GetProtectedBranchByID getting protected branch by ID
287-
func GetProtectedBranchByID(id int64) (*ProtectedBranch, error) {
288-
rel := &ProtectedBranch{}
289-
has, err := x.ID(id).Get(rel)
290-
if err != nil {
291-
return nil, err
292-
}
293-
if !has {
294-
return nil, nil
295-
}
296-
return rel, nil
297-
}
298-
299280
// WhitelistOptions represent all sorts of whitelists used for protected branches
300281
type WhitelistOptions struct {
301282
UserIDs []int64

models/issue_label.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -510,19 +510,6 @@ func GetLabelIDsInOrgByNames(orgID int64, labelNames []string) ([]int64, error)
510510
Find(&labelIDs)
511511
}
512512

513-
// GetLabelIDsInOrgsByNames returns a list of labelIDs by names in one of the given
514-
// organization.
515-
// it silently ignores label names that do not belong to the organization.
516-
func GetLabelIDsInOrgsByNames(orgIDs []int64, labelNames []string) ([]int64, error) {
517-
labelIDs := make([]int64, 0, len(labelNames))
518-
return labelIDs, x.Table("label").
519-
In("org_id", orgIDs).
520-
In("name", labelNames).
521-
Asc("name").
522-
Cols("id").
523-
Find(&labelIDs)
524-
}
525-
526513
// GetLabelInOrgByID returns a label by ID in given organization.
527514
func GetLabelInOrgByID(orgID, labelID int64) (*Label, error) {
528515
return getLabelInOrgByID(x, orgID, labelID)

models/lfs.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,11 +131,11 @@ func (repo *Repository) CountLFSMetaObjects() (int64, error) {
131131
func LFSObjectAccessible(user *User, oid string) (bool, error) {
132132
if user.IsAdmin {
133133
count, err := x.Count(&LFSMetaObject{Pointer: lfs.Pointer{Oid: oid}})
134-
return (count > 0), err
134+
return count > 0, err
135135
}
136136
cond := accessibleRepositoryCondition(user)
137137
count, err := x.Where(cond).Join("INNER", "repository", "`lfs_meta_object`.repository_id = `repository`.id").Count(&LFSMetaObject{Pointer: lfs.Pointer{Oid: oid}})
138-
return (count > 0), err
138+
return count > 0, err
139139
}
140140

141141
// LFSAutoAssociate auto associates accessible LFSMetaObjects

models/repo_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func TestGetRepositoryCount(t *testing.T) {
7575
assert.NoError(t, err2)
7676
assert.NoError(t, err3)
7777
assert.Equal(t, int64(3), count)
78-
assert.Equal(t, (privateCount + publicCount), count)
78+
assert.Equal(t, privateCount+publicCount, count)
7979
}
8080

8181
func TestGetPublicRepositoryCount(t *testing.T) {

models/user.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,6 @@ const (
7676
)
7777

7878
var (
79-
// ErrUserNotKeyOwner user does not own this key error
80-
ErrUserNotKeyOwner = errors.New("User does not own this public key")
81-
8279
// ErrEmailNotExist e-mail does not exist error
8380
ErrEmailNotExist = errors.New("E-mail does not exist")
8481

models/user_heatmap.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func getUserHeatmapData(user *User, team *Team, doer *User) ([]*UserHeatmapData,
6565
Select(groupBy+" AS timestamp, count(user_id) as contributions").
6666
Table("action").
6767
Where(cond).
68-
And("created_unix > ?", (timeutil.TimeStampNow() - 31536000)).
68+
And("created_unix > ?", timeutil.TimeStampNow()-31536000).
6969
GroupBy(groupByName).
7070
OrderBy("timestamp").
7171
Find(&hdata)

models/user_openid.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ func GetUserOpenIDs(uid int64) ([]*UserOpenID, error) {
3535
return openids, nil
3636
}
3737

38+
// isOpenIDUsed returns true if the openid has been used.
3839
func isOpenIDUsed(e Engine, uri string) (bool, error) {
3940
if len(uri) == 0 {
4041
return true, nil
@@ -43,11 +44,6 @@ func isOpenIDUsed(e Engine, uri string) (bool, error) {
4344
return e.Get(&UserOpenID{URI: uri})
4445
}
4546

46-
// IsOpenIDUsed returns true if the openid has been used.
47-
func IsOpenIDUsed(openid string) (bool, error) {
48-
return isOpenIDUsed(x, openid)
49-
}
50-
5147
// NOTE: make sure openid.URI is normalized already
5248
func addUserOpenID(e Engine, openid *UserOpenID) error {
5349
used, err := isOpenIDUsed(e, openid.URI)

modules/markup/common/linkify.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,7 @@ func (s *linkifyParser) Parse(parent ast.Node, block text.Reader, pc parser.Cont
122122
}
123123
}
124124
}
125-
if m == nil {
126-
return nil
127-
}
125+
128126
if consumes != 0 {
129127
s := segment.WithStop(segment.Start + 1)
130128
ast.MergeOrAppendTextSegment(parent, s)

modules/process/manager.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ package process
88
import (
99
"bytes"
1010
"context"
11-
"errors"
1211
"fmt"
1312
"io"
1413
"os/exec"
@@ -22,10 +21,8 @@ import (
2221
// then we delete the singleton.
2322

2423
var (
25-
// ErrExecTimeout represent a timeout error
26-
ErrExecTimeout = errors.New("Process execution timeout")
27-
manager *Manager
28-
managerInit sync.Once
24+
manager *Manager
25+
managerInit sync.Once
2926

3027
// DefaultContext is the default context to run processing commands in
3128
DefaultContext = context.Background()

modules/queue/bytefifo.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type UniqueByteFIFO interface {
2323
Has(data []byte) (bool, error)
2424
}
2525

26-
var _ (ByteFIFO) = &DummyByteFIFO{}
26+
var _ ByteFIFO = &DummyByteFIFO{}
2727

2828
// DummyByteFIFO represents a dummy fifo
2929
type DummyByteFIFO struct{}
@@ -48,7 +48,7 @@ func (*DummyByteFIFO) Len() int64 {
4848
return 0
4949
}
5050

51-
var _ (UniqueByteFIFO) = &DummyUniqueByteFIFO{}
51+
var _ UniqueByteFIFO = &DummyUniqueByteFIFO{}
5252

5353
// DummyUniqueByteFIFO represents a dummy unique fifo
5454
type DummyUniqueByteFIFO struct {

modules/queue/helper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func toConfig(exemplar, cfg interface{}) (interface{}, error) {
5050
var err error
5151

5252
configBytes, err = json.Marshal(cfg)
53-
ok = (err == nil)
53+
ok = err == nil
5454
}
5555
if !ok {
5656
// no ... we've tried hard enough at this point - throw an error!

modules/queue/queue_bytefifo.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type ByteFIFOQueueConfiguration struct {
2121
Name string
2222
}
2323

24-
var _ (Queue) = &ByteFIFOQueue{}
24+
var _ Queue = &ByteFIFOQueue{}
2525

2626
// ByteFIFOQueue is a Queue formed from a ByteFIFO and WorkerPool
2727
type ByteFIFOQueue struct {
@@ -196,7 +196,7 @@ func (q *ByteFIFOQueue) IsTerminated() <-chan struct{} {
196196
return q.terminated
197197
}
198198

199-
var _ (UniqueQueue) = &ByteFIFOUniqueQueue{}
199+
var _ UniqueQueue = &ByteFIFOUniqueQueue{}
200200

201201
// ByteFIFOUniqueQueue represents a UniqueQueue formed from a UniqueByteFifo
202202
type ByteFIFOUniqueQueue struct {

modules/queue/queue_disk.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func NewLevelQueue(handle HandlerFunc, cfg, exemplar interface{}) (Queue, error)
5555
return queue, nil
5656
}
5757

58-
var _ (ByteFIFO) = &LevelQueueByteFIFO{}
58+
var _ ByteFIFO = &LevelQueueByteFIFO{}
5959

6060
// LevelQueueByteFIFO represents a ByteFIFO formed from a LevelQueue
6161
type LevelQueueByteFIFO struct {

modules/queue/queue_redis.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ type redisClient interface {
6969
Close() error
7070
}
7171

72-
var _ (ByteFIFO) = &RedisByteFIFO{}
72+
var _ ByteFIFO = &RedisByteFIFO{}
7373

7474
// RedisByteFIFO represents a ByteFIFO formed from a redisClient
7575
type RedisByteFIFO struct {

modules/queue/unique_queue_disk.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func NewLevelUniqueQueue(handle HandlerFunc, cfg, exemplar interface{}) (Queue,
5959
return queue, nil
6060
}
6161

62-
var _ (UniqueByteFIFO) = &LevelUniqueQueueByteFIFO{}
62+
var _ UniqueByteFIFO = &LevelUniqueQueueByteFIFO{}
6363

6464
// LevelUniqueQueueByteFIFO represents a ByteFIFO formed from a LevelUniqueQueue
6565
type LevelUniqueQueueByteFIFO struct {

modules/queue/unique_queue_redis.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func NewRedisUniqueQueue(handle HandlerFunc, cfg, exemplar interface{}) (Queue,
6262
return queue, nil
6363
}
6464

65-
var _ (UniqueByteFIFO) = &RedisUniqueByteFIFO{}
65+
var _ UniqueByteFIFO = &RedisUniqueByteFIFO{}
6666

6767
// RedisUniqueByteFIFO represents a UniqueByteFIFO formed from a redisClient
6868
type RedisUniqueByteFIFO struct {

modules/references/references.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ func convertFullHTMLReferencesToShortRefs(re *regexp.Regexp, contentBytes *[]byt
296296

297297
// our new section has length endPos - match[3]
298298
// our old section has length match[9] - match[3]
299-
(*contentBytes) = (*contentBytes)[:len((*contentBytes))-match[9]+endPos]
299+
*contentBytes = (*contentBytes)[:len(*contentBytes)-match[9]+endPos]
300300
pos = endPos
301301
}
302302
}

modules/repofiles/action.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ func UpdateIssuesCommit(doer *models.User, repo *models.Repository, commits []*r
201201
continue
202202
}
203203
}
204-
close := (ref.Action == references.XRefActionCloses)
204+
close := ref.Action == references.XRefActionCloses
205205
if close && len(ref.TimeLog) > 0 {
206206
if err := issueAddTime(refIssue, doer, c.Timestamp, ref.TimeLog); err != nil {
207207
return err

modules/setting/setting.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,6 @@ var (
318318
LogRootPath string
319319
DisableRouterLog bool
320320
RouterLogLevel log.Level
321-
RouterLogMode string
322321
EnableAccessLog bool
323322
AccessLogTemplate string
324323
EnableXORMLog bool
@@ -408,10 +407,6 @@ var (
408407
IsWindows bool
409408
HasRobotsTxt bool
410409
InternalToken string // internal access token
411-
412-
// UILocation is the location on the UI, so that we can display the time on UI.
413-
// Currently only show the default time.Local, it could be added to app.ini after UI is ready
414-
UILocation = time.Local
415410
)
416411

417412
// IsProd if it's a production mode

modules/storage/helper.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func toConfig(exemplar, cfg interface{}) (interface{}, error) {
5050
var err error
5151

5252
configBytes, err = json.Marshal(cfg)
53-
ok = (err == nil)
53+
ok = err == nil
5454
}
5555
if !ok {
5656
// no ... we've tried hard enough at this point - throw an error!

modules/storage/storage.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ import (
1919
var (
2020
// ErrURLNotSupported represents url is not supported
2121
ErrURLNotSupported = errors.New("url method not supported")
22-
// ErrIterateObjectsNotSupported represents IterateObjects not supported
23-
ErrIterateObjectsNotSupported = errors.New("iterateObjects method not supported")
2422
)
2523

2624
// ErrInvalidConfiguration is called when there is invalid configuration for a storage

routers/api/v1/org/team.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ func SearchTeam(ctx *context.APIContext) {
660660
UserID: ctx.User.ID,
661661
Keyword: strings.TrimSpace(ctx.Query("q")),
662662
OrgID: ctx.Org.Organization.ID,
663-
IncludeDesc: (ctx.Query("include_desc") == "" || ctx.QueryBool("include_desc")),
663+
IncludeDesc: ctx.Query("include_desc") == "" || ctx.QueryBool("include_desc"),
664664
ListOptions: listOptions,
665665
}
666666

routers/api/v1/repo/issue.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ func SearchIssues(ctx *context.APIContext) {
141141
keyword = ""
142142
}
143143
var issueIDs []int64
144-
var labelIDs []int64
145144
if len(keyword) > 0 && len(repoIDs) > 0 {
146145
if issueIDs, err = issue_indexer.SearchIssuesByKeyword(repoIDs, keyword); err != nil {
147146
ctx.Error(http.StatusInternalServerError, "SearchIssuesByKeyword", err)
@@ -176,7 +175,7 @@ func SearchIssues(ctx *context.APIContext) {
176175

177176
// Only fetch the issues if we either don't have a keyword or the search returned issues
178177
// This would otherwise return all issues if no issues were found by the search.
179-
if len(keyword) == 0 || len(issueIDs) > 0 || len(labelIDs) > 0 {
178+
if len(keyword) == 0 || len(issueIDs) > 0 || len(includedLabelNames) > 0 {
180179
issuesOpt := &models.IssuesOptions{
181180
ListOptions: models.ListOptions{
182181
Page: ctx.QueryInt("page"),
@@ -675,7 +674,7 @@ func EditIssue(ctx *context.APIContext) {
675674
}
676675
}
677676
if form.State != nil {
678-
issue.IsClosed = (api.StateClosed == api.StateType(*form.State))
677+
issue.IsClosed = api.StateClosed == api.StateType(*form.State)
679678
}
680679
statusChangeComment, titleChanged, err := models.UpdateIssueByAPI(issue, ctx.User)
681680
if err != nil {

routers/api/v1/repo/pull.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ func EditPullRequest(ctx *context.APIContext) {
580580
}
581581

582582
if form.State != nil {
583-
issue.IsClosed = (api.StateClosed == api.StateType(*form.State))
583+
issue.IsClosed = api.StateClosed == api.StateType(*form.State)
584584
}
585585
statusChangeComment, titleChanged, err := models.UpdateIssueByAPI(issue, ctx.User)
586586
if err != nil {

routers/events/events.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ func Events(ctx *context.Context) {
3232

3333
if !ctx.IsSigned {
3434
// Return unauthorized status event
35-
event := (&eventsource.Event{
35+
event := &eventsource.Event{
3636
Name: "close",
3737
Data: "unauthorized",
38-
})
38+
}
3939
_, _ = event.WriteTo(ctx)
4040
ctx.Resp.Flush()
4141
return
@@ -137,10 +137,10 @@ loop:
137137
break loop
138138
}
139139
// Replace the event - we don't want to expose the session ID to the user
140-
event = (&eventsource.Event{
140+
event = &eventsource.Event{
141141
Name: "logout",
142142
Data: "elsewhere",
143-
})
143+
}
144144
}
145145

146146
_, err := event.WriteTo(ctx.Resp)

0 commit comments

Comments
 (0)