Skip to content

Commit e0bed86

Browse files
committed
Add stylecheck linter
1 parent 607a7d0 commit e0bed86

File tree

13 files changed

+157
-154
lines changed

13 files changed

+157
-154
lines changed

.golangci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ linters:
2323
- unconvert
2424
- wastedassign
2525
- nolintlint
26+
- stylecheck
2627
enable-all: false
2728
disable-all: true
2829
fast: false
@@ -36,6 +37,8 @@ run:
3637
- web_src
3738

3839
linters-settings:
40+
stylecheck:
41+
checks: ["all", "-ST1005", "-ST1003"]
3942
nakedret:
4043
max-func-lines: 5
4144
gocritic:

cmd/hook.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,7 @@ func writeDataPktLine(out io.Writer, data []byte) error {
792792
if err != nil {
793793
return fail("Internal Server Error", "Pkt-Line response failed: %v", err)
794794
}
795-
if 4 != lr {
795+
if lr != 4 {
796796
return fail("Internal Server Error", "Pkt-Line response failed: %v", err)
797797
}
798798

models/issues/issue_project.go

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,46 +14,46 @@ import (
1414
)
1515

1616
// LoadProject load the project the issue was assigned to
17-
func (i *Issue) LoadProject() (err error) {
18-
return i.loadProject(db.DefaultContext)
17+
func (issue *Issue) LoadProject() (err error) {
18+
return issue.loadProject(db.DefaultContext)
1919
}
2020

21-
func (i *Issue) loadProject(ctx context.Context) (err error) {
22-
if i.Project == nil {
21+
func (issue *Issue) loadProject(ctx context.Context) (err error) {
22+
if issue.Project == nil {
2323
var p project_model.Project
2424
if _, err = db.GetEngine(ctx).Table("project").
2525
Join("INNER", "project_issue", "project.id=project_issue.project_id").
26-
Where("project_issue.issue_id = ?", i.ID).
26+
Where("project_issue.issue_id = ?", issue.ID).
2727
Get(&p); err != nil {
2828
return err
2929
}
30-
i.Project = &p
30+
issue.Project = &p
3131
}
3232
return err
3333
}
3434

3535
// ProjectID return project id if issue was assigned to one
36-
func (i *Issue) ProjectID() int64 {
37-
return i.projectID(db.DefaultContext)
36+
func (issue *Issue) ProjectID() int64 {
37+
return issue.projectID(db.DefaultContext)
3838
}
3939

40-
func (i *Issue) projectID(ctx context.Context) int64 {
40+
func (issue *Issue) projectID(ctx context.Context) int64 {
4141
var ip project_model.ProjectIssue
42-
has, err := db.GetEngine(ctx).Where("issue_id=?", i.ID).Get(&ip)
42+
has, err := db.GetEngine(ctx).Where("issue_id=?", issue.ID).Get(&ip)
4343
if err != nil || !has {
4444
return 0
4545
}
4646
return ip.ProjectID
4747
}
4848

4949
// ProjectBoardID return project board id if issue was assigned to one
50-
func (i *Issue) ProjectBoardID() int64 {
51-
return i.projectBoardID(db.DefaultContext)
50+
func (issue *Issue) ProjectBoardID() int64 {
51+
return issue.projectBoardID(db.DefaultContext)
5252
}
5353

54-
func (i *Issue) projectBoardID(ctx context.Context) int64 {
54+
func (issue *Issue) projectBoardID(ctx context.Context) int64 {
5555
var ip project_model.ProjectIssue
56-
has, err := db.GetEngine(ctx).Where("issue_id=?", i.ID).Get(&ip)
56+
has, err := db.GetEngine(ctx).Where("issue_id=?", issue.ID).Get(&ip)
5757
if err != nil || !has {
5858
return 0
5959
}

models/issues/issue_xref.go

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -231,44 +231,44 @@ func (issue *Issue) verifyReferencedIssue(stdCtx context.Context, ctx *crossRefe
231231
}
232232

233233
// AddCrossReferences add cross references
234-
func (comment *Comment) AddCrossReferences(stdCtx context.Context, doer *user_model.User, removeOld bool) error {
235-
if comment.Type != CommentTypeCode && comment.Type != CommentTypeComment {
234+
func (c *Comment) AddCrossReferences(stdCtx context.Context, doer *user_model.User, removeOld bool) error {
235+
if c.Type != CommentTypeCode && c.Type != CommentTypeComment {
236236
return nil
237237
}
238-
if err := comment.LoadIssueCtx(stdCtx); err != nil {
238+
if err := c.LoadIssueCtx(stdCtx); err != nil {
239239
return err
240240
}
241241
ctx := &crossReferencesContext{
242242
Type: CommentTypeCommentRef,
243243
Doer: doer,
244-
OrigIssue: comment.Issue,
245-
OrigComment: comment,
244+
OrigIssue: c.Issue,
245+
OrigComment: c,
246246
RemoveOld: removeOld,
247247
}
248-
return comment.Issue.createCrossReferences(stdCtx, ctx, "", comment.Content)
248+
return c.Issue.createCrossReferences(stdCtx, ctx, "", c.Content)
249249
}
250250

251-
func (comment *Comment) neuterCrossReferences(ctx context.Context) error {
252-
return neuterCrossReferences(ctx, comment.IssueID, comment.ID)
251+
func (c *Comment) neuterCrossReferences(ctx context.Context) error {
252+
return neuterCrossReferences(ctx, c.IssueID, c.ID)
253253
}
254254

255255
// LoadRefComment loads comment that created this reference from database
256-
func (comment *Comment) LoadRefComment() (err error) {
257-
if comment.RefComment != nil {
256+
func (c *Comment) LoadRefComment() (err error) {
257+
if c.RefComment != nil {
258258
return nil
259259
}
260-
comment.RefComment, err = GetCommentByID(db.DefaultContext, comment.RefCommentID)
260+
c.RefComment, err = GetCommentByID(db.DefaultContext, c.RefCommentID)
261261
return err
262262
}
263263

264264
// LoadRefIssue loads comment that created this reference from database
265-
func (comment *Comment) LoadRefIssue() (err error) {
266-
if comment.RefIssue != nil {
265+
func (c *Comment) LoadRefIssue() (err error) {
266+
if c.RefIssue != nil {
267267
return nil
268268
}
269-
comment.RefIssue, err = GetIssueByID(db.DefaultContext, comment.RefIssueID)
269+
c.RefIssue, err = GetIssueByID(db.DefaultContext, c.RefIssueID)
270270
if err == nil {
271-
err = comment.RefIssue.LoadRepo(db.DefaultContext)
271+
err = c.RefIssue.LoadRepo(db.DefaultContext)
272272
}
273273
return err
274274
}
@@ -279,44 +279,44 @@ func CommentTypeIsRef(t CommentType) bool {
279279
}
280280

281281
// RefCommentHTMLURL returns the HTML URL for the comment that created this reference
282-
func (comment *Comment) RefCommentHTMLURL() string {
282+
func (c *Comment) RefCommentHTMLURL() string {
283283
// Edge case for when the reference is inside the title or the description of the referring issue
284-
if comment.RefCommentID == 0 {
285-
return comment.RefIssueHTMLURL()
284+
if c.RefCommentID == 0 {
285+
return c.RefIssueHTMLURL()
286286
}
287-
if err := comment.LoadRefComment(); err != nil { // Silently dropping errors :unamused:
288-
log.Error("LoadRefComment(%d): %v", comment.RefCommentID, err)
287+
if err := c.LoadRefComment(); err != nil { // Silently dropping errors :unamused:
288+
log.Error("LoadRefComment(%d): %v", c.RefCommentID, err)
289289
return ""
290290
}
291-
return comment.RefComment.HTMLURL()
291+
return c.RefComment.HTMLURL()
292292
}
293293

294294
// RefIssueHTMLURL returns the HTML URL of the issue where this reference was created
295-
func (comment *Comment) RefIssueHTMLURL() string {
296-
if err := comment.LoadRefIssue(); err != nil { // Silently dropping errors :unamused:
297-
log.Error("LoadRefIssue(%d): %v", comment.RefCommentID, err)
295+
func (c *Comment) RefIssueHTMLURL() string {
296+
if err := c.LoadRefIssue(); err != nil { // Silently dropping errors :unamused:
297+
log.Error("LoadRefIssue(%d): %v", c.RefCommentID, err)
298298
return ""
299299
}
300-
return comment.RefIssue.HTMLURL()
300+
return c.RefIssue.HTMLURL()
301301
}
302302

303303
// RefIssueTitle returns the title of the issue where this reference was created
304-
func (comment *Comment) RefIssueTitle() string {
305-
if err := comment.LoadRefIssue(); err != nil { // Silently dropping errors :unamused:
306-
log.Error("LoadRefIssue(%d): %v", comment.RefCommentID, err)
304+
func (c *Comment) RefIssueTitle() string {
305+
if err := c.LoadRefIssue(); err != nil { // Silently dropping errors :unamused:
306+
log.Error("LoadRefIssue(%d): %v", c.RefCommentID, err)
307307
return ""
308308
}
309-
return comment.RefIssue.Title
309+
return c.RefIssue.Title
310310
}
311311

312312
// RefIssueIdent returns the user friendly identity (e.g. "#1234") of the issue where this reference was created
313-
func (comment *Comment) RefIssueIdent() string {
314-
if err := comment.LoadRefIssue(); err != nil { // Silently dropping errors :unamused:
315-
log.Error("LoadRefIssue(%d): %v", comment.RefCommentID, err)
313+
func (c *Comment) RefIssueIdent() string {
314+
if err := c.LoadRefIssue(); err != nil { // Silently dropping errors :unamused:
315+
log.Error("LoadRefIssue(%d): %v", c.RefCommentID, err)
316316
return ""
317317
}
318318
// FIXME: check this name for cross-repository references (#7901 if it gets merged)
319-
return fmt.Sprintf("#%d", comment.RefIssue.Index)
319+
return fmt.Sprintf("#%d", c.RefIssue.Index)
320320
}
321321

322322
// __________ .__ .__ __________ __

models/packages/package_version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ func (opts *PackageSearchOptions) toConds() builder.Cond {
235235
}
236236

237237
if !opts.HasFiles.IsNone() {
238-
var filesCond builder.Cond = builder.Exists(builder.Select("package_file.id").From("package_file").Where(builder.Expr("package_file.version_id = package_version.id")))
238+
filesCond := builder.Exists(builder.Select("package_file.id").From("package_file").Where(builder.Expr("package_file.version_id = package_version.id")))
239239

240240
if opts.HasFiles.IsFalse() {
241241
filesCond = builder.Not{filesCond}

models/project/issue.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func MoveIssuesOnProjectBoard(board *Board, sortedIssueIDs map[int64]int64) erro
103103
})
104104
}
105105

106-
func (pb *Board) removeIssues(ctx context.Context) error {
107-
_, err := db.GetEngine(ctx).Exec("UPDATE `project_issue` SET project_board_id = 0 WHERE project_board_id = ? ", pb.ID)
106+
func (b *Board) removeIssues(ctx context.Context) error {
107+
_, err := db.GetEngine(ctx).Exec("UPDATE `project_issue` SET project_board_id = 0 WHERE project_board_id = ? ", b.ID)
108108
return err
109109
}

models/user/search.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func (opts *SearchUserOptions) toSearchQueryBase() *xorm.Session {
5959
}
6060

6161
if opts.Actor != nil {
62-
var exprCond builder.Cond = builder.Expr("org_user.org_id = `user`.id")
62+
exprCond := builder.Expr("org_user.org_id = `user`.id")
6363

6464
// If Admin - they see all users!
6565
if !opts.Actor.IsAdmin {

modules/base/natural_sort.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func isDecimal(r rune) bool {
5555
}
5656

5757
func compareByNumbers(str1 string, pos1 int, str2 string, pos2 int) (i1, i2 int, less, equal bool) {
58-
var d1, d2 bool = true, true
58+
d1, d2 := true, true
5959
var dec1, dec2 string
6060
for d1 || d2 {
6161
if d1 {

modules/indexer/code/bleve.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ func (b *BleveIndexer) Search(ctx context.Context, repoIDs []int64, language, ke
392392

393393
searchResults := make([]*SearchResult, len(result.Hits))
394394
for i, hit := range result.Hits {
395-
var startIndex, endIndex int = -1, -1
395+
startIndex, endIndex := -1, -1
396396
for _, locations := range hit.Locations["Content"] {
397397
location := locations[0]
398398
locationStart := int(location.Start)

modules/migration/issue.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ type Issue struct {
3030
}
3131

3232
// GetExternalName ExternalUserMigrated interface
33-
func (i *Issue) GetExternalName() string { return i.PosterName }
33+
func (issue *Issue) GetExternalName() string { return issue.PosterName }
3434

3535
// GetExternalID ExternalUserMigrated interface
36-
func (i *Issue) GetExternalID() int64 { return i.PosterID }
36+
func (issue *Issue) GetExternalID() int64 { return issue.PosterID }
3737

38-
func (i *Issue) GetLocalIndex() int64 { return i.Number }
39-
func (i *Issue) GetForeignIndex() int64 { return i.ForeignIndex }
40-
func (i *Issue) GetContext() DownloaderContext { return i.Context }
38+
func (issue *Issue) GetLocalIndex() int64 { return issue.Number }
39+
func (issue *Issue) GetForeignIndex() int64 { return issue.ForeignIndex }
40+
func (issue *Issue) GetContext() DownloaderContext { return issue.Context }

routers/private/serv.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ func ServCommand(ctx *context.PrivateContext) {
142142
if repo_model.IsErrRepoNotExist(err) {
143143
repoExist = false
144144
for _, verb := range ctx.FormStrings("verb") {
145-
if "git-upload-pack" == verb {
145+
if verb == "git-upload-pack" {
146146
// User is fetching/cloning a non-existent repository
147147
log.Warn("Failed authentication attempt (cannot find repository: %s/%s) from %s", results.OwnerName, results.RepoName, ctx.RemoteAddr())
148148
ctx.JSON(http.StatusNotFound, private.ErrServCommand{

routers/web/web.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ func Routes() *web.Route {
138138

139139
// redirect default favicon to the path of the custom favicon with a default as a fallback
140140
routes.Get("/favicon.ico", func(w http.ResponseWriter, req *http.Request) {
141-
http.Redirect(w, req, path.Join(setting.StaticURLPrefix, "/assets/img/favicon.png"), 301)
141+
http.Redirect(w, req, path.Join(setting.StaticURLPrefix, "/assets/img/favicon.png"), http.StatusMovedPermanently)
142142
})
143143

144144
common := []interface{}{}

0 commit comments

Comments
 (0)