Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code Formats, Nits & Unused Func/Var deletions #15286

Merged
merged 8 commits into from
Apr 9, 2021
Merged
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
6 changes: 3 additions & 3 deletions cmd/admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ func runDeleteUser(c *cli.Context) error {
return models.DeleteUser(user)
}

func runRepoSyncReleases(c *cli.Context) error {
func runRepoSyncReleases(_ *cli.Context) error {
if err := initDB(); err != nil {
return err
}
Expand Down Expand Up @@ -578,14 +578,14 @@ func getReleaseCount(id int64) (int64, error) {
)
}

func runRegenerateHooks(c *cli.Context) error {
func runRegenerateHooks(_ *cli.Context) error {
if err := initDB(); err != nil {
return err
}
return repo_module.SyncRepositoryHooks(graceful.GetManager().ShutdownContext())
}

func runRegenerateKeys(c *cli.Context) error {
func runRegenerateKeys(_ *cli.Context) error {
if err := initDB(); err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ Gitea or set your environment appropriately.`, "")
}

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

// the environment setted on serv command
repoUser := os.Getenv(models.EnvRepoUsername)
isWiki := (os.Getenv(models.EnvRepoIsWiki) == "true")
isWiki := os.Getenv(models.EnvRepoIsWiki) == "true"
repoName := os.Getenv(models.EnvRepoName)
pusherID, _ := strconv.ParseInt(os.Getenv(models.EnvPusherID), 10, 64)
pusherName := os.Getenv(models.EnvPusherName)
Expand Down
19 changes: 0 additions & 19 deletions models/branches.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,6 @@ func (protectBranch *ProtectedBranch) IsProtectedFile(patterns []glob.Glob, path
return r
}

// GetProtectedBranchByRepoID getting protected branch by repo ID
func GetProtectedBranchByRepoID(repoID int64) ([]*ProtectedBranch, error) {
protectedBranches := make([]*ProtectedBranch, 0)
return protectedBranches, x.Where("repo_id = ?", repoID).Desc("updated_unix").Find(&protectedBranches)
}

// GetProtectedBranchBy getting protected branch by ID/Name
func GetProtectedBranchBy(repoID int64, branchName string) (*ProtectedBranch, error) {
return getProtectedBranchBy(x, repoID, branchName)
Expand All @@ -283,19 +277,6 @@ func getProtectedBranchBy(e Engine, repoID int64, branchName string) (*Protected
return rel, nil
}

// GetProtectedBranchByID getting protected branch by ID
func GetProtectedBranchByID(id int64) (*ProtectedBranch, error) {
rel := &ProtectedBranch{}
has, err := x.ID(id).Get(rel)
if err != nil {
return nil, err
}
if !has {
return nil, nil
}
return rel, nil
}

// WhitelistOptions represent all sorts of whitelists used for protected branches
type WhitelistOptions struct {
UserIDs []int64
Expand Down
13 changes: 0 additions & 13 deletions models/issue_label.go
Original file line number Diff line number Diff line change
Expand Up @@ -510,19 +510,6 @@ func GetLabelIDsInOrgByNames(orgID int64, labelNames []string) ([]int64, error)
Find(&labelIDs)
}

// GetLabelIDsInOrgsByNames returns a list of labelIDs by names in one of the given
// organization.
// it silently ignores label names that do not belong to the organization.
func GetLabelIDsInOrgsByNames(orgIDs []int64, labelNames []string) ([]int64, error) {
labelIDs := make([]int64, 0, len(labelNames))
return labelIDs, x.Table("label").
In("org_id", orgIDs).
In("name", labelNames).
Asc("name").
Cols("id").
Find(&labelIDs)
}

// GetLabelInOrgByID returns a label by ID in given organization.
func GetLabelInOrgByID(orgID, labelID int64) (*Label, error) {
return getLabelInOrgByID(x, orgID, labelID)
Expand Down
4 changes: 2 additions & 2 deletions models/lfs.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,11 @@ func (repo *Repository) CountLFSMetaObjects() (int64, error) {
func LFSObjectAccessible(user *User, oid string) (bool, error) {
if user.IsAdmin {
count, err := x.Count(&LFSMetaObject{Pointer: lfs.Pointer{Oid: oid}})
return (count > 0), err
return count > 0, err
}
cond := accessibleRepositoryCondition(user)
count, err := x.Where(cond).Join("INNER", "repository", "`lfs_meta_object`.repository_id = `repository`.id").Count(&LFSMetaObject{Pointer: lfs.Pointer{Oid: oid}})
return (count > 0), err
return count > 0, err
}

// LFSAutoAssociate auto associates accessible LFSMetaObjects
Expand Down
2 changes: 1 addition & 1 deletion models/repo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func TestGetRepositoryCount(t *testing.T) {
assert.NoError(t, err2)
assert.NoError(t, err3)
assert.Equal(t, int64(3), count)
assert.Equal(t, (privateCount + publicCount), count)
assert.Equal(t, privateCount+publicCount, count)
}

func TestGetPublicRepositoryCount(t *testing.T) {
Expand Down
3 changes: 0 additions & 3 deletions models/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,6 @@ const (
)

var (
// ErrUserNotKeyOwner user does not own this key error
ErrUserNotKeyOwner = errors.New("User does not own this public key")

// ErrEmailNotExist e-mail does not exist error
ErrEmailNotExist = errors.New("E-mail does not exist")

Expand Down
2 changes: 1 addition & 1 deletion models/user_heatmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func getUserHeatmapData(user *User, team *Team, doer *User) ([]*UserHeatmapData,
Select(groupBy+" AS timestamp, count(user_id) as contributions").
Table("action").
Where(cond).
And("created_unix > ?", (timeutil.TimeStampNow() - 31536000)).
And("created_unix > ?", timeutil.TimeStampNow()-31536000).
GroupBy(groupByName).
OrderBy("timestamp").
Find(&hdata)
Expand Down
6 changes: 1 addition & 5 deletions models/user_openid.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ func GetUserOpenIDs(uid int64) ([]*UserOpenID, error) {
return openids, nil
}

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

// IsOpenIDUsed returns true if the openid has been used.
func IsOpenIDUsed(openid string) (bool, error) {
return isOpenIDUsed(x, openid)
}

// NOTE: make sure openid.URI is normalized already
func addUserOpenID(e Engine, openid *UserOpenID) error {
used, err := isOpenIDUsed(e, openid.URI)
Expand Down
4 changes: 1 addition & 3 deletions modules/markup/common/linkify.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,7 @@ func (s *linkifyParser) Parse(parent ast.Node, block text.Reader, pc parser.Cont
}
}
}
if m == nil {
return nil
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove these?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because of dead code

see L100 & L110

If we like to keep it, we need a reason we should write down here ...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lunny do we have a reason to keep it?

if consumes != 0 {
s := segment.WithStop(segment.Start + 1)
ast.MergeOrAppendTextSegment(parent, s)
Expand Down
7 changes: 2 additions & 5 deletions modules/process/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ package process
import (
"bytes"
"context"
"errors"
"fmt"
"io"
"os/exec"
Expand All @@ -22,10 +21,8 @@ import (
// then we delete the singleton.

var (
// ErrExecTimeout represent a timeout error
ErrExecTimeout = errors.New("Process execution timeout")
manager *Manager
managerInit sync.Once
manager *Manager
managerInit sync.Once

// DefaultContext is the default context to run processing commands in
DefaultContext = context.Background()
Expand Down
4 changes: 2 additions & 2 deletions modules/queue/bytefifo.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type UniqueByteFIFO interface {
Has(data []byte) (bool, error)
}

var _ (ByteFIFO) = &DummyByteFIFO{}
var _ ByteFIFO = &DummyByteFIFO{}

// DummyByteFIFO represents a dummy fifo
type DummyByteFIFO struct{}
Expand All @@ -48,7 +48,7 @@ func (*DummyByteFIFO) Len() int64 {
return 0
}

var _ (UniqueByteFIFO) = &DummyUniqueByteFIFO{}
var _ UniqueByteFIFO = &DummyUniqueByteFIFO{}

// DummyUniqueByteFIFO represents a dummy unique fifo
type DummyUniqueByteFIFO struct {
Expand Down
2 changes: 1 addition & 1 deletion modules/queue/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func toConfig(exemplar, cfg interface{}) (interface{}, error) {
var err error

configBytes, err = json.Marshal(cfg)
ok = (err == nil)
ok = err == nil
}
if !ok {
// no ... we've tried hard enough at this point - throw an error!
Expand Down
4 changes: 2 additions & 2 deletions modules/queue/queue_bytefifo.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type ByteFIFOQueueConfiguration struct {
Name string
}

var _ (Queue) = &ByteFIFOQueue{}
var _ Queue = &ByteFIFOQueue{}

// ByteFIFOQueue is a Queue formed from a ByteFIFO and WorkerPool
type ByteFIFOQueue struct {
Expand Down Expand Up @@ -196,7 +196,7 @@ func (q *ByteFIFOQueue) IsTerminated() <-chan struct{} {
return q.terminated
}

var _ (UniqueQueue) = &ByteFIFOUniqueQueue{}
var _ UniqueQueue = &ByteFIFOUniqueQueue{}

// ByteFIFOUniqueQueue represents a UniqueQueue formed from a UniqueByteFifo
type ByteFIFOUniqueQueue struct {
Expand Down
2 changes: 1 addition & 1 deletion modules/queue/queue_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func NewLevelQueue(handle HandlerFunc, cfg, exemplar interface{}) (Queue, error)
return queue, nil
}

var _ (ByteFIFO) = &LevelQueueByteFIFO{}
var _ ByteFIFO = &LevelQueueByteFIFO{}

// LevelQueueByteFIFO represents a ByteFIFO formed from a LevelQueue
type LevelQueueByteFIFO struct {
Expand Down
2 changes: 1 addition & 1 deletion modules/queue/queue_redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ type redisClient interface {
Close() error
}

var _ (ByteFIFO) = &RedisByteFIFO{}
var _ ByteFIFO = &RedisByteFIFO{}

// RedisByteFIFO represents a ByteFIFO formed from a redisClient
type RedisByteFIFO struct {
Expand Down
2 changes: 1 addition & 1 deletion modules/queue/unique_queue_disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func NewLevelUniqueQueue(handle HandlerFunc, cfg, exemplar interface{}) (Queue,
return queue, nil
}

var _ (UniqueByteFIFO) = &LevelUniqueQueueByteFIFO{}
var _ UniqueByteFIFO = &LevelUniqueQueueByteFIFO{}

// LevelUniqueQueueByteFIFO represents a ByteFIFO formed from a LevelUniqueQueue
type LevelUniqueQueueByteFIFO struct {
Expand Down
2 changes: 1 addition & 1 deletion modules/queue/unique_queue_redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func NewRedisUniqueQueue(handle HandlerFunc, cfg, exemplar interface{}) (Queue,
return queue, nil
}

var _ (UniqueByteFIFO) = &RedisUniqueByteFIFO{}
var _ UniqueByteFIFO = &RedisUniqueByteFIFO{}

// RedisUniqueByteFIFO represents a UniqueByteFIFO formed from a redisClient
type RedisUniqueByteFIFO struct {
Expand Down
2 changes: 1 addition & 1 deletion modules/references/references.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ func convertFullHTMLReferencesToShortRefs(re *regexp.Regexp, contentBytes *[]byt

// our new section has length endPos - match[3]
// our old section has length match[9] - match[3]
(*contentBytes) = (*contentBytes)[:len((*contentBytes))-match[9]+endPos]
*contentBytes = (*contentBytes)[:len(*contentBytes)-match[9]+endPos]
pos = endPos
}
}
Expand Down
2 changes: 1 addition & 1 deletion modules/repofiles/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ func UpdateIssuesCommit(doer *models.User, repo *models.Repository, commits []*r
continue
}
}
close := (ref.Action == references.XRefActionCloses)
close := ref.Action == references.XRefActionCloses
if close && len(ref.TimeLog) > 0 {
if err := issueAddTime(refIssue, doer, c.Timestamp, ref.TimeLog); err != nil {
return err
Expand Down
5 changes: 0 additions & 5 deletions modules/setting/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,6 @@ var (
LogRootPath string
DisableRouterLog bool
RouterLogLevel log.Level
RouterLogMode string
EnableAccessLog bool
AccessLogTemplate string
EnableXORMLog bool
Expand Down Expand Up @@ -408,10 +407,6 @@ var (
IsWindows bool
HasRobotsTxt bool
InternalToken string // internal access token

// UILocation is the location on the UI, so that we can display the time on UI.
// Currently only show the default time.Local, it could be added to app.ini after UI is ready
UILocation = time.Local
)

// IsProd if it's a production mode
Expand Down
2 changes: 1 addition & 1 deletion modules/storage/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func toConfig(exemplar, cfg interface{}) (interface{}, error) {
var err error

configBytes, err = json.Marshal(cfg)
ok = (err == nil)
ok = err == nil
}
if !ok {
// no ... we've tried hard enough at this point - throw an error!
Expand Down
2 changes: 0 additions & 2 deletions modules/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ import (
var (
// ErrURLNotSupported represents url is not supported
ErrURLNotSupported = errors.New("url method not supported")
// ErrIterateObjectsNotSupported represents IterateObjects not supported
ErrIterateObjectsNotSupported = errors.New("iterateObjects method not supported")
)

// ErrInvalidConfiguration is called when there is invalid configuration for a storage
Expand Down
2 changes: 1 addition & 1 deletion routers/api/v1/org/team.go
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ func SearchTeam(ctx *context.APIContext) {
UserID: ctx.User.ID,
Keyword: strings.TrimSpace(ctx.Query("q")),
OrgID: ctx.Org.Organization.ID,
IncludeDesc: (ctx.Query("include_desc") == "" || ctx.QueryBool("include_desc")),
IncludeDesc: ctx.Query("include_desc") == "" || ctx.QueryBool("include_desc"),
ListOptions: listOptions,
}

Expand Down
5 changes: 2 additions & 3 deletions routers/api/v1/repo/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ func SearchIssues(ctx *context.APIContext) {
keyword = ""
}
var issueIDs []int64
var labelIDs []int64
if len(keyword) > 0 && len(repoIDs) > 0 {
if issueIDs, err = issue_indexer.SearchIssuesByKeyword(repoIDs, keyword); err != nil {
ctx.Error(http.StatusInternalServerError, "SearchIssuesByKeyword", err)
Expand Down Expand Up @@ -176,7 +175,7 @@ func SearchIssues(ctx *context.APIContext) {

// Only fetch the issues if we either don't have a keyword or the search returned issues
// This would otherwise return all issues if no issues were found by the search.
if len(keyword) == 0 || len(issueIDs) > 0 || len(labelIDs) > 0 {
if len(keyword) == 0 || len(issueIDs) > 0 || len(includedLabelNames) > 0 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This maybe a bug but not a refactor?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

didn't dig into it yet - posible

Copy link
Member Author

@6543 6543 Apr 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

look's like in an edge case the label filter potentially is not applied, but I could not hit it, so It's a code improvement to prevent becoming a bug in the future

issuesOpt := &models.IssuesOptions{
ListOptions: models.ListOptions{
Page: ctx.QueryInt("page"),
Expand Down Expand Up @@ -675,7 +674,7 @@ func EditIssue(ctx *context.APIContext) {
}
}
if form.State != nil {
issue.IsClosed = (api.StateClosed == api.StateType(*form.State))
issue.IsClosed = api.StateClosed == api.StateType(*form.State)
}
statusChangeComment, titleChanged, err := models.UpdateIssueByAPI(issue, ctx.User)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion routers/api/v1/repo/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ func EditPullRequest(ctx *context.APIContext) {
}

if form.State != nil {
issue.IsClosed = (api.StateClosed == api.StateType(*form.State))
issue.IsClosed = api.StateClosed == api.StateType(*form.State)
}
statusChangeComment, titleChanged, err := models.UpdateIssueByAPI(issue, ctx.User)
if err != nil {
Expand Down
8 changes: 4 additions & 4 deletions routers/events/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ func Events(ctx *context.Context) {

if !ctx.IsSigned {
// Return unauthorized status event
event := (&eventsource.Event{
event := &eventsource.Event{
Name: "close",
Data: "unauthorized",
})
}
_, _ = event.WriteTo(ctx)
ctx.Resp.Flush()
return
Expand Down Expand Up @@ -137,10 +137,10 @@ loop:
break loop
}
// Replace the event - we don't want to expose the session ID to the user
event = (&eventsource.Event{
event = &eventsource.Event{
Name: "logout",
Data: "elsewhere",
})
}
}

_, err := event.WriteTo(ctx.Resp)
Expand Down
Loading