Skip to content

Commit 6322fc1

Browse files
authored
Merge pull request #437 from Unpackerr/dn2_linter
update linter
2 parents 9447777 + 30d0897 commit 6322fc1

7 files changed

Lines changed: 42 additions & 35 deletions

File tree

.github/workflows/codetests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ jobs:
3939
- name: golangci-lint
4040
uses: golangci/golangci-lint-action@v6
4141
with:
42-
version: 'v1.55'
42+
version: 'v1.59'
4343

4444
golangci-linux:
4545
# description: "Runs golangci-lint on linux against linux and windows."
@@ -60,4 +60,4 @@ jobs:
6060
- name: golangci-lint
6161
uses: golangci/golangci-lint-action@v6
6262
with:
63-
version: 'v1.55'
63+
version: 'v1.59'

.golangci.yml

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,8 @@ linters:
22
enable-all: true
33
disable:
44
# deprecated
5-
- maligned
6-
- scopelint
7-
- interfacer
8-
- golint
9-
- exhaustivestruct
10-
- nosnakecase
11-
- structcheck
12-
- deadcode
13-
- varcheck
14-
- ifshort
15-
# unneeded (broken because of generics)
16-
- rowserrcheck
17-
- wastedassign
18-
- sqlclosecheck
19-
- contextcheck
5+
- execinquery
6+
- gomnd
207
# unused
218
- exhaustruct
229
- exhaustive

pkg/ui/ui_other.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package ui
44

55
import (
6+
"errors"
67
"fmt"
78
"io"
89
"os/exec"
@@ -27,7 +28,7 @@ func StartCmd(c string, v ...string) error {
2728
}
2829

2930
// ErrUnsupported is just an error.
30-
var ErrUnsupported = fmt.Errorf("unsupported OS")
31+
var ErrUnsupported = errors.New("unsupported OS")
3132

3233
// OpenCmd opens anything.
3334
func OpenCmd(_ ...string) error {

pkg/unpackerr/apps.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package unpackerr
22

33
import (
4+
"errors"
45
"fmt"
56
"strings"
67
"sync"
@@ -32,7 +33,7 @@ const (
3233

3334
// Application validation errors.
3435
var (
35-
ErrInvalidURL = fmt.Errorf("provided application URL is invalid")
36+
ErrInvalidURL = errors.New("provided application URL is invalid")
3637
ErrInvalidKey = fmt.Errorf("provided application API Key is invalid, must be %d characters", apiKeyLength)
3738
)
3839

@@ -78,7 +79,7 @@ type workThread struct {
7879

7980
func (u *Unpackerr) watchWorkThread() {
8081
workers := u.Parallel
81-
if workers > 4 { //nolint:gomnd // 4 == the four starr apps.
82+
if workers > 4 { //nolint:mnd // 4 == the four starr apps.
8283
workers = 4
8384
}
8485

@@ -122,19 +123,26 @@ func (u *Unpackerr) retrieveAppQueues() {
122123
// validateApps is broken-out into this file to make adding new apps easier.
123124
func (u *Unpackerr) validateApps() error {
124125
for _, validate := range []func() error{
125-
u.validateCmdhook,
126126
u.validateLidarr,
127127
u.validateRadarr,
128128
u.validateReadarr,
129129
u.validateSonarr,
130130
u.validateWhisparr,
131-
u.validateWebhook,
132131
} {
133132
if err := validate(); err != nil {
134133
return err
135134
}
136135
}
137136

137+
for _, validate := range []func() error{
138+
u.validateCmdhook,
139+
u.validateWebhook,
140+
} {
141+
if err := validate(); err != nil {
142+
u.Errorf("Config Warning: %v", err)
143+
}
144+
}
145+
138146
return nil
139147
}
140148

pkg/unpackerr/cmdhook.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package unpackerr
33
import (
44
"bytes"
55
"context"
6+
"errors"
67
"fmt"
78
"os"
89
"os/exec"
@@ -15,7 +16,7 @@ import (
1516

1617
// Errors produced by this file.
1718
var (
18-
ErrCmdhookNoCmd = fmt.Errorf("cmdhook without a command configured; fix it")
19+
ErrCmdhookNoCmd = errors.New("cmdhook without a command configured; fix it")
1920
)
2021

2122
func (u *Unpackerr) validateCmdhook() error {
@@ -47,13 +48,12 @@ func (u *Unpackerr) runCmdhookWithLog(hook *WebhookConfig, payload *WebhookPaylo
4748

4849
hook.Lock() // we only lock for the integer increments.
4950
defer hook.Unlock()
50-
51-
hook.posts++
51+
hook.posts++ //nolint:wsl
5252

5353
switch {
5454
case err != nil:
5555
u.Errorf("Command Hook (%s) %s: %v: %s", payload.Event, hook.Name, err, out.String())
56-
hook.fails++
56+
hook.fails++ //nolint:wsl
5757
case hook.Silent || out == nil:
5858
u.Printf("[Cmdhook] Queue: %d/%d. Ran command %s", len(u.hookChan), cap(u.hookChan), hook.Name)
5959
default:
@@ -63,6 +63,10 @@ func (u *Unpackerr) runCmdhookWithLog(hook *WebhookConfig, payload *WebhookPaylo
6363
}
6464

6565
func (u *Unpackerr) runCmdhook(hook *WebhookConfig, payload *WebhookPayload) (*bytes.Buffer, error) {
66+
if hook.Command == "" {
67+
return nil, ErrCmdhookNoCmd
68+
}
69+
6670
payload.Config = hook
6771

6872
env, err := cnfg.MarshalENV(payload, "UN")
@@ -122,7 +126,7 @@ func (u *Unpackerr) logCmdhook() {
122126
pfx = " => Command Hook Config: 1 cmd"
123127
} else {
124128
u.Printf(" => Command Hook Configs: %d commands", len(u.Cmdhook))
125-
pfx = " => Command"
129+
pfx = " => Command" //nolint:wsl
126130
}
127131

128132
for _, f := range u.Cmdhook {

pkg/unpackerr/folder.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ func (u *Unpackerr) logFolders() {
8484
if epath = ""; folder.ExtractPath != "" {
8585
epath = ", extract to: " + folder.ExtractPath
8686
}
87+
8788
u.Printf(" => Path: %s%s (delete after:%v, delete orig:%v, log file: %v, move back:%v, isos:%v)",
8889
folder.Path, epath, folder.DeleteAfter, folder.DeleteOrig, !folder.DisableLog, folder.MoveBack, folder.ExtractISOs)
8990
}

pkg/unpackerr/webhook.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bytes"
55
"context"
66
"crypto/tls"
7+
"errors"
78
"fmt"
89
"io"
910
"net/http"
@@ -48,8 +49,8 @@ type hookQueueItem struct {
4849

4950
// Errors produced by this file.
5051
var (
51-
ErrInvalidStatus = fmt.Errorf("invalid HTTP status reply")
52-
ErrWebhookNoURL = fmt.Errorf("webhook without a URL configured; fix it")
52+
ErrInvalidStatus = errors.New("invalid HTTP status reply")
53+
ErrWebhookNoURL = errors.New("webhook without a URL configured; fix it")
5354
)
5455

5556
// ExtractStatuses allows us to create a custom environment variable unmarshaller.
@@ -174,8 +175,13 @@ func (u *Unpackerr) sendWebhookWithLog(hook *WebhookConfig, payload *WebhookPayl
174175

175176
// Send marshals an interface{} into json and POSTs it to a URL.
176177
func (w *WebhookConfig) Send(body io.Reader) ([]byte, error) {
178+
if w.URL == "" {
179+
return nil, ErrWebhookNoURL
180+
}
181+
177182
w.Lock()
178183
defer w.Unlock()
184+
179185
w.posts++
180186

181187
ctx, cancel := context.WithTimeout(context.Background(), w.Timeout.Duration+time.Second)
@@ -195,7 +201,7 @@ func (w *WebhookConfig) send(ctx context.Context, body io.Reader) ([]byte, error
195201
return nil, fmt.Errorf("creating request: %w", err)
196202
}
197203

198-
req.Header.Set("content-type", w.CType)
204+
req.Header.Set("Content-Type", w.CType)
199205

200206
res, err := w.client.Do(req)
201207
if err != nil {
@@ -266,24 +272,24 @@ func (u *Unpackerr) logWebhook() {
266272
pfx = " => Webhook Config: 1 URL"
267273
} else {
268274
u.Printf(" => Webhook Configs: %d URLs", len(u.Webhook))
269-
pfx = " => URL"
275+
pfx = " => URL" //nolint:wsl
270276
}
271277

272278
for _, f := range u.Webhook {
273279
if ex = ""; f.TmplPath != "" {
274-
ex = fmt.Sprintf(", template: %s, content_type: %s", f.TmplPath, f.CType)
280+
ex = ", template: " + f.TmplPath + ", content_type: " + f.CType
275281
}
276282

277283
if f.Channel != "" {
278-
ex += fmt.Sprintf(", channel: %s", f.Channel)
284+
ex += ", channel: " + f.Channel
279285
}
280286

281287
if f.Nickname != "" {
282-
ex += fmt.Sprintf(", nickname: %s", f.Nickname)
288+
ex += ", nickname: " + f.Nickname
283289
}
284290

285291
if len(f.Exclude) > 0 {
286-
ex += fmt.Sprintf(", exclude: %q", strings.Join(f.Exclude, "; "))
292+
ex += ", exclude: \"" + strings.Join(f.Exclude, "; ") + `"`
287293
}
288294

289295
u.Printf("%s: %s, timeout: %v, ignore ssl: %v, silent: %v%s, events: %q",

0 commit comments

Comments
 (0)