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

Enable forbidigo linter #24278

Merged
merged 6 commits into from
Apr 24, 2023
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
4 changes: 4 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ linters:
- depguard
- dupl
- errcheck
- forbidigo
- gocritic
# - gocyclo # The cyclomatic complexety of a lot of functions is too high, we should refactor those another time.
- gofmt
Expand Down Expand Up @@ -105,6 +106,9 @@ issues:
- errcheck
- dupl
- gosec
- path: cmd
linters:
- forbidigo
- linters:
- dupl
text: "webhook"
Expand Down
1 change: 1 addition & 0 deletions contrib/backport/backport.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2023 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

//nolint:forbidigo
package main

import (
Expand Down
1 change: 1 addition & 0 deletions contrib/fixtures/fixture_generation.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2020 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

//nolint:forbidigo
package main

import (
Expand Down
1 change: 1 addition & 0 deletions models/migrations/base/tests.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2022 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

//nolint:forbidigo
package base

import (
Expand Down
2 changes: 1 addition & 1 deletion models/migrations/v1_11/v112.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func RemoveAttachmentMissedRepo(x *xorm.Engine) error {
for i := 0; i < len(attachments); i++ {
uuid := attachments[i].UUID
if err = util.RemoveAll(filepath.Join(setting.Attachment.Path, uuid[0:1], uuid[1:2], uuid)); err != nil {
fmt.Printf("Error: %v", err)
fmt.Printf("Error: %v", err) //nolint:forbidigo
}
}

Expand Down
1 change: 1 addition & 0 deletions models/unittest/fixtures.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2021 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

//nolint:forbidigo
package unittest

import (
Expand Down
2 changes: 1 addition & 1 deletion modules/doctor/paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func isWritableDir(path string) error {
return err
}
if err := os.Remove(tmpFile.Name()); err != nil {
fmt.Printf("Warning: can't remove temporary file: '%s'\n", tmpFile.Name())
fmt.Printf("Warning: can't remove temporary file: '%s'\n", tmpFile.Name()) //nolint:forbidigo
}
tmpFile.Close()
return nil
Expand Down
4 changes: 2 additions & 2 deletions modules/log/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ func (m *MultiChannelledLog) Start() {
for _, logger := range m.loggers {
err := logger.LogEvent(event)
if err != nil {
fmt.Println(err)
fmt.Println(err) //nolint:forbidigo
}
}
m.rwmutex.RUnlock()
Expand Down Expand Up @@ -379,7 +379,7 @@ func (m *MultiChannelledLog) emptyQueue() bool {
for _, logger := range m.loggers {
err := logger.LogEvent(event)
if err != nil {
fmt.Println(err)
fmt.Println(err) //nolint:forbidigo
}
}
m.rwmutex.RUnlock()
Expand Down
2 changes: 0 additions & 2 deletions modules/queue/unique_queue_disk_channel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
package queue

import (
"fmt"
"strconv"
"sync"
"testing"
Expand All @@ -17,7 +16,6 @@ import (

func TestPersistableChannelUniqueQueue(t *testing.T) {
tmpDir := t.TempDir()
fmt.Printf("TempDir %s\n", tmpDir)
_ = log.NewLogger(1000, "console", "console", `{"level":"warn","stacktracelevel":"NONE","stderr":true}`)

// Common function to create the Queue
Expand Down
2 changes: 1 addition & 1 deletion modules/web/routing/logger_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const (
type Printer func(trigger Event, record *requestRecord)

type requestRecordsManager struct {
print Printer
print Printer //nolint:forbidigo

lock sync.Mutex

Expand Down
1 change: 1 addition & 0 deletions tests/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// This is primarily coped from /tests/integration/integration_test.go
// TODO: Move common functions to shared file

//nolint:forbidigo
package e2e

import (
Expand Down
1 change: 1 addition & 0 deletions tests/integration/integration_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2017 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

//nolint:forbidigo
package integration

import (
Expand Down
1 change: 0 additions & 1 deletion tests/integration/repo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,6 @@ func TestViewRepoDirectoryReadme(t *testing.T) {

htmlDoc := NewHTMLParser(t, resp.Body)
_, exists := htmlDoc.doc.Find(".file-view").Attr("class")
fmt.Printf("%s", resp.Body)

assert.False(t, exists, "README should not have rendered")
})
Expand Down
1 change: 1 addition & 0 deletions tests/test_utils.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2017 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

//nolint:forbidigo
package tests

import (
Expand Down