Lint: Resolve linter issues

occurred with new Go / golangci-lint version

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2024-02-18 13:42:00 +01:00
parent e0e9f6d80a
commit 673ed1e29a
Signed by: luzifer
SSH key fingerprint: SHA256:/xtE5lCgiRDQr8SLxHMS92ZBlACmATUmF1crK16Ks4E
16 changed files with 31 additions and 31 deletions

View file

@ -11,7 +11,7 @@ func init() {
cli.Add(cliRegistryEntry{
Name: "actor-docs",
Description: "Generate markdown documentation for available actors",
Run: func(args []string) error {
Run: func([]string) error {
doc, err := generateActorDocs()
if err != nil {
return errors.Wrap(err, "generating actor docs")

View file

@ -9,7 +9,7 @@ func init() {
cli.Add(cliRegistryEntry{
Name: "reset-secrets",
Description: "Remove encrypted data to reset encryption passphrase",
Run: func(args []string) error {
Run: func([]string) error {
if err := accessService.RemoveAllExtendedTwitchCredentials(); err != nil {
return errors.Wrap(err, "resetting Twitch credentials")
}

View file

@ -11,7 +11,7 @@ func init() {
cli.Add(cliRegistryEntry{
Name: "tpl-docs",
Description: "Generate markdown documentation for available template functions",
Run: func(args []string) error {
Run: func([]string) error {
doc, err := generateTplDocs()
if err != nil {
return errors.Wrap(err, "generating template docs")

View file

@ -6,7 +6,7 @@ func init() {
cli.Add(cliRegistryEntry{
Name: "validate-config",
Description: "Try to load configuration file and report errors if any",
Run: func(args []string) error {
Run: func([]string) error {
return errors.Wrap(
loadConfig(cfg.Config),
"loading config",

View file

@ -46,7 +46,7 @@ func init() {
}
func registerEditorFrontend() {
router.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
router.HandleFunc("/", func(w http.ResponseWriter, _ *http.Request) {
f, err := configEditorFrontend.Open("editor/index.html")
if err != nil {
http.Error(w, errors.Wrap(err, "opening index.html").Error(), http.StatusNotFound)
@ -56,7 +56,7 @@ func registerEditorFrontend() {
io.Copy(w, f) //nolint:errcheck,gosec
})
router.HandleFunc("/editor/vars.json", func(w http.ResponseWriter, r *http.Request) {
router.HandleFunc("/editor/vars.json", func(w http.ResponseWriter, _ *http.Request) {
if err := json.NewEncoder(w).Encode(struct {
DefaultBotScopes []string
IRCBadges []string

View file

@ -11,7 +11,7 @@ import (
)
func init() {
tplFuncs.Register("arg", func(m *irc.Message, r *plugins.Rule, fields *plugins.FieldCollection) interface{} {
tplFuncs.Register("arg", func(m *irc.Message, _ *plugins.Rule, _ *plugins.FieldCollection) interface{} {
return func(arg int) (string, error) {
msgParts := strings.Split(m.Trailing(), " ")
if len(msgParts) <= arg {
@ -30,7 +30,7 @@ func init() {
},
})
tplFuncs.Register("chatterHasBadge", func(m *irc.Message, r *plugins.Rule, fields *plugins.FieldCollection) interface{} {
tplFuncs.Register("chatterHasBadge", func(m *irc.Message, _ *plugins.Rule, _ *plugins.FieldCollection) interface{} {
return func(badge string) bool {
badges := twitch.ParseBadgeLevels(m)
return badges.Has(badge)
@ -57,7 +57,7 @@ func init() {
},
)
tplFuncs.Register("group", func(m *irc.Message, r *plugins.Rule, fields *plugins.FieldCollection) interface{} {
tplFuncs.Register("group", func(m *irc.Message, r *plugins.Rule, _ *plugins.FieldCollection) interface{} {
return func(idx int, fallback ...string) (string, error) {
fields := r.GetMatchMessage().FindStringSubmatch(m.Trailing())
if len(fields) <= idx {
@ -94,7 +94,7 @@ func init() {
},
)
tplFuncs.Register("tag", func(m *irc.Message, r *plugins.Rule, fields *plugins.FieldCollection) interface{} {
tplFuncs.Register("tag", func(m *irc.Message, _ *plugins.Rule, _ *plugins.FieldCollection) interface{} {
return func(tag string) string { return m.Tags[tag] }
}, plugins.TemplateFuncDocumentation{
Description: "Takes the message sent to the channel, returns the value of the tag specified",

View file

@ -135,7 +135,7 @@ func Register(args plugins.RegistrationArguments) (err error) {
return fmt.Errorf("registering API route: %w", err)
}
args.RegisterTemplateFunction("channelCounter", func(m *irc.Message, r *plugins.Rule, fields *plugins.FieldCollection) interface{} {
args.RegisterTemplateFunction("channelCounter", func(_ *irc.Message, _ *plugins.Rule, fields *plugins.FieldCollection) interface{} {
return func(name string) (string, error) {
channel, err := fields.String("channel")
if err != nil {

View file

@ -37,7 +37,7 @@ func actionDelete(channel, _, msgid, _ string) (err error) {
}
func getActionTimeout(duration time.Duration) actionFn {
return func(channel, match, msgid, user string) error {
return func(channel, match, _, user string) error {
return errors.Wrap(
botTwitchClient.BanUser(
context.Background(),

View file

@ -93,7 +93,7 @@ func Register(args plugins.RegistrationArguments) (err error) {
return fmt.Errorf("registering API: %w", err)
}
args.RegisterTemplateFunction("lastQuoteIndex", func(m *irc.Message, r *plugins.Rule, fields *plugins.FieldCollection) interface{} {
args.RegisterTemplateFunction("lastQuoteIndex", func(m *irc.Message, _ *plugins.Rule, _ *plugins.FieldCollection) interface{} {
return func() (int, error) {
return getMaxQuoteIdx(db, plugins.DeriveChannel(m, nil))
}

View file

@ -20,7 +20,7 @@ const moduleName = "raffle"
var apiRoutes = []plugins.HTTPRouteRegistrationArgs{
{
Description: "Lists all raffles known to the bot",
HandlerFunc: handleWrap(func(w http.ResponseWriter, r *http.Request, _ map[string]uint64) (any, error) {
HandlerFunc: handleWrap(func(_ http.ResponseWriter, _ *http.Request, _ map[string]uint64) (any, error) {
ras, err := dbc.List()
return ras, errors.Wrap(err, "fetching raffles from database")
}, nil),
@ -34,7 +34,7 @@ var apiRoutes = []plugins.HTTPRouteRegistrationArgs{
{
Description: "Creates a new raffle based on the data in the body",
HandlerFunc: handleWrap(func(w http.ResponseWriter, r *http.Request, _ map[string]uint64) (any, error) {
HandlerFunc: handleWrap(func(_ http.ResponseWriter, r *http.Request, _ map[string]uint64) (any, error) {
var ra raffle
if err := json.NewDecoder(r.Body).Decode(&ra); err != nil {
return nil, errors.Wrap(err, "parsing raffle from body")
@ -52,7 +52,7 @@ var apiRoutes = []plugins.HTTPRouteRegistrationArgs{
{
Description: "Deletes raffle by given ID including all entries",
HandlerFunc: handleWrap(func(w http.ResponseWriter, r *http.Request, ids map[string]uint64) (any, error) {
HandlerFunc: handleWrap(func(_ http.ResponseWriter, _ *http.Request, ids map[string]uint64) (any, error) {
return nil, errors.Wrap(dbc.Delete(ids["id"]), "fetching raffle from database")
}, []string{"id"}),
Method: http.MethodDelete,
@ -71,7 +71,7 @@ var apiRoutes = []plugins.HTTPRouteRegistrationArgs{
{
Description: "Gets raffle by given ID including all entries",
HandlerFunc: handleWrap(func(w http.ResponseWriter, r *http.Request, ids map[string]uint64) (any, error) {
HandlerFunc: handleWrap(func(_ http.ResponseWriter, _ *http.Request, ids map[string]uint64) (any, error) {
ra, err := dbc.Get(ids["id"])
return ra, errors.Wrap(err, "fetching raffle from database")
}, []string{"id"}),
@ -91,7 +91,7 @@ var apiRoutes = []plugins.HTTPRouteRegistrationArgs{
{
Description: "Updates the given raffle (needs to include the whole object, not just changed fields)",
HandlerFunc: handleWrap(func(w http.ResponseWriter, r *http.Request, ids map[string]uint64) (any, error) {
HandlerFunc: handleWrap(func(_ http.ResponseWriter, r *http.Request, ids map[string]uint64) (any, error) {
var ra raffle
if err := json.NewDecoder(r.Body).Decode(&ra); err != nil {
return nil, errors.Wrap(err, "parsing raffle from body")
@ -119,7 +119,7 @@ var apiRoutes = []plugins.HTTPRouteRegistrationArgs{
{
Description: "Resets the raffle (remove entries, reset status & start/close time) given by its ID",
HandlerFunc: handleWrap(func(w http.ResponseWriter, r *http.Request, ids map[string]uint64) (any, error) {
HandlerFunc: handleWrap(func(_ http.ResponseWriter, _ *http.Request, ids map[string]uint64) (any, error) {
return nil, errors.Wrap(dbc.Reset(ids["id"]), "resetting raffle")
}, []string{"id"}),
Method: http.MethodPut,
@ -138,7 +138,7 @@ var apiRoutes = []plugins.HTTPRouteRegistrationArgs{
{
Description: "Duplicates the raffle given by its ID",
HandlerFunc: handleWrap(func(w http.ResponseWriter, r *http.Request, ids map[string]uint64) (any, error) {
HandlerFunc: handleWrap(func(_ http.ResponseWriter, _ *http.Request, ids map[string]uint64) (any, error) {
return nil, errors.Wrap(dbc.Clone(ids["id"]), "cloning raffle")
}, []string{"id"}),
Method: http.MethodPut,
@ -157,7 +157,7 @@ var apiRoutes = []plugins.HTTPRouteRegistrationArgs{
{
Description: "Closes the raffle given by its ID",
HandlerFunc: handleWrap(func(w http.ResponseWriter, r *http.Request, ids map[string]uint64) (any, error) {
HandlerFunc: handleWrap(func(_ http.ResponseWriter, _ *http.Request, ids map[string]uint64) (any, error) {
return nil, errors.Wrap(dbc.Close(ids["id"]), "closing raffle")
}, []string{"id"}),
Method: http.MethodPut,
@ -176,7 +176,7 @@ var apiRoutes = []plugins.HTTPRouteRegistrationArgs{
{
Description: "Picks a winner for the given raffle (this does NOT close the raffle, use only on closed raffle!)",
HandlerFunc: handleWrap(func(w http.ResponseWriter, r *http.Request, ids map[string]uint64) (any, error) {
HandlerFunc: handleWrap(func(_ http.ResponseWriter, _ *http.Request, ids map[string]uint64) (any, error) {
return nil, errors.Wrap(dbc.PickWinner(ids["id"]), "picking winner")
}, []string{"id"}),
Method: http.MethodPut,
@ -195,7 +195,7 @@ var apiRoutes = []plugins.HTTPRouteRegistrationArgs{
{
Description: "Re-opens a raffle for additional entries, only Status and CloseAt are modified",
HandlerFunc: handleWrap(func(w http.ResponseWriter, r *http.Request, ids map[string]uint64) (any, error) {
HandlerFunc: handleWrap(func(_ http.ResponseWriter, r *http.Request, ids map[string]uint64) (any, error) {
dur, err := strconv.ParseInt(r.URL.Query().Get("duration"), 10, 64)
if err != nil {
return nil, errors.Wrap(err, "parsing duration")
@ -227,7 +227,7 @@ var apiRoutes = []plugins.HTTPRouteRegistrationArgs{
{
Description: "Starts a raffle making it available for entries",
HandlerFunc: handleWrap(func(w http.ResponseWriter, r *http.Request, ids map[string]uint64) (any, error) {
HandlerFunc: handleWrap(func(_ http.ResponseWriter, _ *http.Request, ids map[string]uint64) (any, error) {
return nil, errors.Wrap(dbc.Start(ids["id"]), "starting raffle")
}, []string{"id"}),
Method: http.MethodPut,
@ -246,7 +246,7 @@ var apiRoutes = []plugins.HTTPRouteRegistrationArgs{
{
Description: "Dismisses a previously picked winner and picks a new one",
HandlerFunc: handleWrap(func(w http.ResponseWriter, r *http.Request, ids map[string]uint64) (any, error) {
HandlerFunc: handleWrap(func(_ http.ResponseWriter, _ *http.Request, ids map[string]uint64) (any, error) {
return nil, errors.Wrap(dbc.RedrawWinner(ids["id"], ids["winner"]), "re-picking winner")
}, []string{"id", "winner"}),
Method: http.MethodPut,

View file

@ -99,7 +99,7 @@ func (r resolver) resolveFinal(link string, cookieJar *cookiejar.Jar, callStack
}
client := &http.Client{
CheckRedirect: func(req *http.Request, via []*http.Request) error {
CheckRedirect: func(*http.Request, []*http.Request) error {
return http.ErrUseLastResponse
},
Jar: cookieJar,

View file

@ -182,7 +182,7 @@ func main() {
router.Use(corsMiddleware)
router.HandleFunc("/openapi.html", handleSwaggerHTML)
router.HandleFunc("/openapi.json", handleSwaggerRequest)
router.HandleFunc("/selfcheck", func(w http.ResponseWriter, r *http.Request) {
router.HandleFunc("/selfcheck", func(w http.ResponseWriter, _ *http.Request) {
http.Error(w, runID, http.StatusOK)
})

View file

@ -23,7 +23,7 @@ func CopyObjects(src, target *gorm.DB, objects ...any) (err error) {
return errors.Wrap(err, "cleaning target table")
}
if err = src.FindInBatches(copySlice, copyBatchSize, func(tx *gorm.DB, _ int) error {
if err = src.FindInBatches(copySlice, copyBatchSize, func(*gorm.DB, int) error {
if err = target.Save(copySlice).Error; err != nil {
if errors.Is(err, gorm.ErrEmptySlice) {
// That's fine and no reason to exit here

View file

@ -24,7 +24,7 @@ type (
StartedAt time.Time `json:"started_at"`
Language string `json:"language"`
ThumbnailURL string `json:"thumbnail_url"`
TagIds []string `json:"tag_ids"`
TagIds []string `json:"tag_ids"` //revive:disable-line:var-naming // Disabled to prevent breaking change
IsMature bool `json:"is_mature"`
}
)

View file

@ -34,7 +34,7 @@ func loadPlugins(pluginDir string) error {
args := getRegistrationArguments()
return errors.Wrap(filepath.Walk(pluginDir, func(currentPath string, info os.FileInfo, err error) error {
return errors.Wrap(filepath.Walk(pluginDir, func(currentPath string, _ os.FileInfo, err error) error {
if err != nil {
return err
}

View file

@ -141,7 +141,7 @@ func TestAllowExecuteDisableOnTemplate(t *testing.T) {
} {
// We don't test the message formatter here but only the disable functionality
// so we fake the result of the evaluation
r.msgFormatter = func(tplString string, m *irc.Message, r *Rule, fields *FieldCollection) (string, error) {
r.msgFormatter = func(string, *irc.Message, *Rule, *FieldCollection) (string, error) {
return msg, nil
}