Skip to content

Commit

Permalink
Lint all the things. (#165)
Browse files Browse the repository at this point in the history
* lint starrcmd

* lint starr

* lint sonarr

* lint readarr

* lint radarr

* lint prowlarr and lidarr

* rename Itoa to Str

* fix all testifylint

* depguard lint

* lint tagalign

* upgrade linter
  • Loading branch information
davidnewhall authored Jul 6, 2024
1 parent fe2f6f3 commit 9017431
Show file tree
Hide file tree
Showing 159 changed files with 596 additions and 536 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/codetests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: 'v1.57'
version: v1.59
# Runs golangci-lint on linux against linux and windows.
golangci-linux:
strategy:
Expand All @@ -67,4 +67,4 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: 'v1.57'
version: v1.59
39 changes: 16 additions & 23 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,44 @@ issues:
max-issues-per-linter: 0
max-same-issues: 0
exclude-rules:
# Exclude funlen for testing files.
- linters:
- path: 'starrcmd/'
linters:
- nonamedreturns
path: 'starrcmd/'
- linters:
- path: '(.+)_test\.go'
linters:
- gochecknoglobals
- forcetypeassert
- funlen
- lll
- maintidx # uhg.
path: '(.+)_test\.go'
- linters:
- lll
path: 'starrtest/'

linters:
enable-all: true
disable:
# deprecated
- maligned
- scopelint
- interfacer
- golint
- ifshort
- deadcode
- nosnakecase
- structcheck
- varcheck
- gomnd
- execinquery
# unused
- tagliatelle
- exhaustivestruct
- exhaustruct
- dupl
- nlreturn
- tagalign
- depguard
- musttag
- perfsprint # need to fix these
- testifylint # fix these too


linters-settings:
# One day we'll fix all the field alignments. Anyone got a tool that just does it?
#linters-settings:
# govet:
# enable:
# - fieldalignment
depguard:
rules:
main:
files:
- $all
allow:
- $gostd
- github.com/stretchr/testify

run:
timeout: 5m
2 changes: 1 addition & 1 deletion http.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func (c *Config) SetHeaders(req *http.Request) {
req.Header.Set("Accept", "application/json")
}

req.Header.Set("User-Agent", "go-starr: https://"+reflect.TypeOf(Config{}).PkgPath()) //nolint:exhaustivestruct
req.Header.Set("User-Agent", "go-starr: https://"+reflect.TypeOf(Config{}).PkgPath())
req.Header.Set("X-Api-Key", c.APIKey)
}

Expand Down
2 changes: 1 addition & 1 deletion interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func readInitializeJS(input io.Reader) (*InitializeJS, error) { //nolint:cyclop

for scanner.Scan() {
switch split := strings.Fields(scanner.Text()); {
case len(split) < 2: //nolint:gomnd
case len(split) < 2: //nolint:mnd
continue
case split[0] == "apiRoot:":
output.APIRoot = strings.Trim(split[1], `"',`)
Expand Down
12 changes: 6 additions & 6 deletions lidarr/album.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (l *Lidarr) GetAlbumByID(albumID int64) (*Album, error) {
func (l *Lidarr) GetAlbumByIDContext(ctx context.Context, albumID int64) (*Album, error) {
var output Album

req := starr.Request{URI: path.Join(bpAlbum, fmt.Sprint(albumID))}
req := starr.Request{URI: path.Join(bpAlbum, starr.Str(albumID))}
if err := l.GetInto(ctx, req, &output); err != nil {
return nil, fmt.Errorf("api.Get(%s): %w", &req, err)
}
Expand All @@ -152,11 +152,11 @@ func (l *Lidarr) UpdateAlbumContext(ctx context.Context, albumID int64, album *A
var output Album

req := starr.Request{
URI: path.Join(bpAlbum, fmt.Sprint(albumID)),
URI: path.Join(bpAlbum, starr.Str(albumID)),
Query: make(url.Values),
Body: &body,
}
req.Query.Add("moveFiles", fmt.Sprint(moveFiles))
req.Query.Add("moveFiles", starr.Str(moveFiles))

if err := l.PutInto(ctx, req, &output); err != nil {
return nil, fmt.Errorf("api.Put(%s): %w", &req, err)
Expand Down Expand Up @@ -231,9 +231,9 @@ func (l *Lidarr) DeleteAlbum(albumID int64, deleteFiles, addImportExclusion bool
// DeleteAlbumContext removes an album from the database.
// Setting deleteFiles true will delete all content for the album.
func (l *Lidarr) DeleteAlbumContext(ctx context.Context, albumID int64, deleteFiles, addImportExclusion bool) error {
req := starr.Request{URI: path.Join(bpAlbum, fmt.Sprint(albumID)), Query: make(url.Values)}
req.Query.Set("deleteFiles", fmt.Sprint(deleteFiles))
req.Query.Set("addImportListExclusion", fmt.Sprint(addImportExclusion))
req := starr.Request{URI: path.Join(bpAlbum, starr.Str(albumID)), Query: make(url.Values)}
req.Query.Set("deleteFiles", starr.Str(deleteFiles))
req.Query.Set("addImportListExclusion", starr.Str(addImportExclusion))

if err := l.DeleteAny(ctx, req); err != nil {
return fmt.Errorf("api.Delete(%s): %w", &req, err)
Expand Down
12 changes: 6 additions & 6 deletions lidarr/artist.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (l *Lidarr) GetArtistByID(artistID int64) (*Artist, error) {
func (l *Lidarr) GetArtistByIDContext(ctx context.Context, artistID int64) (*Artist, error) {
var output Artist

req := starr.Request{URI: path.Join(bpArtist, fmt.Sprint(artistID))}
req := starr.Request{URI: path.Join(bpArtist, starr.Str(artistID))}
if err := l.GetInto(ctx, req, &output); err != nil {
return nil, fmt.Errorf("api.Get(%s): %w", &req, err)
}
Expand Down Expand Up @@ -129,8 +129,8 @@ func (l *Lidarr) UpdateArtistContext(ctx context.Context, artist *Artist, moveFi
return nil, fmt.Errorf("json.Marshal(%s): %w", bpArtist, err)
}

req := starr.Request{URI: path.Join(bpArtist, fmt.Sprint(artist.ID)), Query: make(url.Values), Body: &body}
req.Query.Add("moveFiles", fmt.Sprint(moveFiles))
req := starr.Request{URI: path.Join(bpArtist, starr.Str(artist.ID)), Query: make(url.Values), Body: &body}
req.Query.Add("moveFiles", starr.Str(moveFiles))

var output Artist
if err := l.PutInto(ctx, req, &output); err != nil {
Expand All @@ -149,9 +149,9 @@ func (l *Lidarr) DeleteArtist(artistID int64, deleteFiles, addImportExclusion bo
// DeleteArtistContext removes an artist from the database.
// Setting deleteFiles true will delete all content for the artist.
func (l *Lidarr) DeleteArtistContext(ctx context.Context, artistID int64, deleteFiles, addImportExclusion bool) error {
req := starr.Request{URI: path.Join(bpArtist, fmt.Sprint(artistID)), Query: make(url.Values)}
req.Query.Set("deleteFiles", fmt.Sprint(deleteFiles))
req.Query.Set("addImportListExclusion", fmt.Sprint(addImportExclusion))
req := starr.Request{URI: path.Join(bpArtist, starr.Str(artistID)), Query: make(url.Values)}
req.Query.Set("deleteFiles", starr.Str(deleteFiles))
req.Query.Set("addImportListExclusion", starr.Str(addImportExclusion))

if err := l.DeleteAny(ctx, req); err != nil {
return fmt.Errorf("api.Delete(%s): %w", &req, err)
Expand Down
2 changes: 1 addition & 1 deletion lidarr/blocklist.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func (l *Lidarr) DeleteBlockList(listID int64) error {

// DeleteBlockListContext removes a single block list item with a context.
func (l *Lidarr) DeleteBlockListContext(ctx context.Context, listID int64) error {
req := starr.Request{URI: path.Join(bpBlocklist, fmt.Sprint(listID))}
req := starr.Request{URI: path.Join(bpBlocklist, starr.Str(listID))}
if err := l.DeleteAny(ctx, req); err != nil {
return fmt.Errorf("api.Delete(%s): %w", &req, err)
}
Expand Down
6 changes: 3 additions & 3 deletions lidarr/calendar.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ func (l *Lidarr) GetCalendarContext(ctx context.Context, filter Calendar) ([]*Al
var output []*Album

req := starr.Request{URI: bpCalendar, Query: make(url.Values)}
req.Query.Add("unmonitored", fmt.Sprint(filter.Unmonitored))
req.Query.Add("includeArtist", fmt.Sprint(filter.IncludeArtist))
req.Query.Add("unmonitored", starr.Str(filter.Unmonitored))
req.Query.Add("includeArtist", starr.Str(filter.IncludeArtist))

if !filter.Start.IsZero() {
req.Query.Add("start", filter.Start.UTC().Format(starr.CalendarTimeFilterFormat))
Expand All @@ -58,7 +58,7 @@ func (l *Lidarr) GetCalendarID(calendarID int64) (*Album, error) {
func (l *Lidarr) GetCalendarIDContext(ctx context.Context, calendarID int64) (*Album, error) {
var output *Album

req := starr.Request{URI: path.Join(bpCalendar, fmt.Sprint(calendarID))}
req := starr.Request{URI: path.Join(bpCalendar, starr.Str(calendarID))}
if err := l.GetInto(ctx, req, &output); err != nil {
return nil, fmt.Errorf("api.Get(%s): %w", &req, err)
}
Expand Down
5 changes: 3 additions & 2 deletions lidarr/calendar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golift.io/starr"
"golift.io/starr/lidarr"
"golift.io/starr/starrtest"
Expand Down Expand Up @@ -195,7 +196,7 @@ func TestGetCalendar(t *testing.T) {
mockServer := test.GetMockServer(t)
client := lidarr.New(starr.New("mockAPIkey", mockServer.URL, 0))
output, err := client.GetCalendar(test.WithRequest.(lidarr.Calendar))
assert.ErrorIs(t, err, test.WithError, "the wrong error was returned")
require.ErrorIs(t, err, test.WithError, "the wrong error was returned")
assert.EqualValues(t, test.WithResponse, output, "make sure ResponseBody and WithResponse are a match")
})
}
Expand Down Expand Up @@ -234,7 +235,7 @@ func TestGetCalendarID(t *testing.T) {
mockServer := test.GetMockServer(t)
client := lidarr.New(starr.New("mockAPIkey", mockServer.URL, 0))
output, err := client.GetCalendarID(test.WithRequest.(int64))
assert.ErrorIs(t, err, test.WithError, "the wrong error was returned")
require.ErrorIs(t, err, test.WithError, "the wrong error was returned")
assert.EqualValues(t, test.WithResponse, output, "make sure ResponseBody and WithResponse are a match")
})
}
Expand Down
2 changes: 1 addition & 1 deletion lidarr/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (l *Lidarr) GetCommandStatusContext(ctx context.Context, commandID int64) (
return &output, nil
}

req := starr.Request{URI: path.Join(bpCommand, fmt.Sprint(commandID))}
req := starr.Request{URI: path.Join(bpCommand, starr.Str(commandID))}
if err := l.GetInto(ctx, req, &output); err != nil {
return nil, fmt.Errorf("api.Get(%s): %w", &req, err)
}
Expand Down
5 changes: 3 additions & 2 deletions lidarr/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golift.io/starr"
"golift.io/starr/lidarr"
"golift.io/starr/starrtest"
Expand Down Expand Up @@ -68,7 +69,7 @@ func TestGetCommands(t *testing.T) {
mockServer := test.GetMockServer(t)
client := lidarr.New(starr.New("mockAPIkey", mockServer.URL, 0))
output, err := client.GetCommands()
assert.ErrorIs(t, err, test.WithError, "error is not the same as expected")
require.ErrorIs(t, err, test.WithError, "error is not the same as expected")
assert.EqualValues(t, test.WithResponse, output, "response is not the same as expected")
})
}
Expand Down Expand Up @@ -142,7 +143,7 @@ func TestSendCommand(t *testing.T) {
mockServer := test.GetMockServer(t)
client := lidarr.New(starr.New("mockAPIkey", mockServer.URL, 0))
output, err := client.SendCommand(test.WithRequest.(*lidarr.CommandRequest))
assert.ErrorIs(t, err, test.WithError, "error is not the same as expected")
require.ErrorIs(t, err, test.WithError, "error is not the same as expected")
assert.EqualValues(t, test.WithResponse, output, "response is not the same as expected")
})
}
Expand Down
6 changes: 3 additions & 3 deletions lidarr/customformat.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (l *Lidarr) GetCustomFormat(customformatID int64) (*CustomFormatOutput, err
func (l *Lidarr) GetCustomFormatContext(ctx context.Context, customformatID int64) (*CustomFormatOutput, error) {
var output CustomFormatOutput

req := starr.Request{URI: path.Join(bpCustomFormat, starr.Itoa(customformatID))}
req := starr.Request{URI: path.Join(bpCustomFormat, starr.Str(customformatID))}
if err := l.GetInto(ctx, req, &output); err != nil {
return nil, fmt.Errorf("api.Get(%s): %w", &req, err)
}
Expand Down Expand Up @@ -121,7 +121,7 @@ func (l *Lidarr) UpdateCustomFormatContext(ctx context.Context,
return nil, fmt.Errorf("json.Marshal(%s): %w", bpCustomFormat, err)
}

req := starr.Request{URI: path.Join(bpCustomFormat, starr.Itoa(format.ID)), Body: &body}
req := starr.Request{URI: path.Join(bpCustomFormat, starr.Str(format.ID)), Body: &body}
if err := l.PutInto(ctx, req, &output); err != nil {
return nil, fmt.Errorf("api.Put(%s): %w", &req, err)
}
Expand All @@ -136,7 +136,7 @@ func (l *Lidarr) DeleteCustomFormat(cfID int64) error {

// DeleteCustomFormatContext deletes a custom format.
func (l *Lidarr) DeleteCustomFormatContext(ctx context.Context, cfID int64) error {
req := starr.Request{URI: path.Join(bpCustomFormat, starr.Itoa(cfID))}
req := starr.Request{URI: path.Join(bpCustomFormat, starr.Str(cfID))}
if err := l.DeleteAny(ctx, req); err != nil {
return fmt.Errorf("api.Delete(%s): %w", &req, err)
}
Expand Down
8 changes: 4 additions & 4 deletions lidarr/downloadclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (l *Lidarr) GetDownloadClient(downloadclientID int64) (*DownloadClientOutpu
func (l *Lidarr) GetDownloadClientContext(ctx context.Context, downloadclientID int64) (*DownloadClientOutput, error) {
var output DownloadClientOutput

req := starr.Request{URI: path.Join(bpDownloadClient, fmt.Sprint(downloadclientID))}
req := starr.Request{URI: path.Join(bpDownloadClient, starr.Str(downloadclientID))}
if err := l.GetInto(ctx, req, &output); err != nil {
return nil, fmt.Errorf("api.Get(%s): %w", &req, err)
}
Expand Down Expand Up @@ -147,9 +147,9 @@ func (l *Lidarr) UpdateDownloadClientContext(ctx context.Context,
}

req := starr.Request{
URI: path.Join(bpDownloadClient, fmt.Sprint(client.ID)),
URI: path.Join(bpDownloadClient, starr.Str(client.ID)),
Body: &body,
Query: url.Values{"forceSave": []string{fmt.Sprint(force)}},
Query: url.Values{"forceSave": []string{starr.Str(force)}},
}
if err := l.PutInto(ctx, req, &output); err != nil {
return nil, fmt.Errorf("api.Put(%s): %w", &req, err)
Expand All @@ -165,7 +165,7 @@ func (l *Lidarr) DeleteDownloadClient(downloadclientID int64) error {

// DeleteDownloadClientContext removes a single download client.
func (l *Lidarr) DeleteDownloadClientContext(ctx context.Context, downloadclientID int64) error {
req := starr.Request{URI: path.Join(bpDownloadClient, fmt.Sprint(downloadclientID))}
req := starr.Request{URI: path.Join(bpDownloadClient, starr.Str(downloadclientID))}
if err := l.DeleteAny(ctx, req); err != nil {
return fmt.Errorf("api.Delete(%s): %w", &req, err)
}
Expand Down
11 changes: 6 additions & 5 deletions lidarr/downloadclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"golift.io/starr"
"golift.io/starr/lidarr"
"golift.io/starr/starrtest"
Expand Down Expand Up @@ -136,7 +137,7 @@ func TestGetDownloadClients(t *testing.T) {
mockServer := test.GetMockServer(t)
client := lidarr.New(starr.New("mockAPIkey", mockServer.URL, 0))
output, err := client.GetDownloadClients()
assert.ErrorIs(t, err, test.WithError, "error is not the same as expected")
require.ErrorIs(t, err, test.WithError, "error is not the same as expected")
assert.EqualValues(t, test.WithResponse, output, "response is not the same as expected")
})
}
Expand Down Expand Up @@ -213,7 +214,7 @@ func TestGetDownloadClient(t *testing.T) {
mockServer := test.GetMockServer(t)
client := lidarr.New(starr.New("mockAPIkey", mockServer.URL, 0))
output, err := client.GetDownloadClient(1)
assert.ErrorIs(t, err, test.WithError, "error is not the same as expected")
require.ErrorIs(t, err, test.WithError, "error is not the same as expected")
assert.EqualValues(t, test.WithResponse, output, "response is not the same as expected")
})
}
Expand Down Expand Up @@ -338,7 +339,7 @@ func TestAddDownloadClient(t *testing.T) {
mockServer := test.GetMockServer(t)
client := lidarr.New(starr.New("mockAPIkey", mockServer.URL, 0))
output, err := client.AddDownloadClient(test.WithRequest.(*lidarr.DownloadClientInput))
assert.ErrorIs(t, err, test.WithError, "error is not the same as expected")
require.ErrorIs(t, err, test.WithError, "error is not the same as expected")
assert.EqualValues(t, test.WithResponse, output, "response is not the same as expected")
})
}
Expand Down Expand Up @@ -465,7 +466,7 @@ func TestUpdateDownloadClient(t *testing.T) {
mockServer := test.GetMockServer(t)
client := lidarr.New(starr.New("mockAPIkey", mockServer.URL, 0))
output, err := client.UpdateDownloadClient(test.WithRequest.(*lidarr.DownloadClientInput), false)
assert.ErrorIs(t, err, test.WithError, "error is not the same as expected")
require.ErrorIs(t, err, test.WithError, "error is not the same as expected")
assert.EqualValues(t, test.WithResponse, output, "response is not the same as expected")
})
}
Expand Down Expand Up @@ -502,7 +503,7 @@ func TestDeleteDownloadClient(t *testing.T) {
mockServer := test.GetMockServer(t)
client := lidarr.New(starr.New("mockAPIkey", mockServer.URL, 0))
err := client.DeleteDownloadClient(test.WithRequest.(int64))
assert.ErrorIs(t, err, test.WithError, "error is not the same as expected")
require.ErrorIs(t, err, test.WithError, "error is not the same as expected")
})
}
}
2 changes: 1 addition & 1 deletion lidarr/downloadclientconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (l *Lidarr) UpdateDownloadClientConfigContext(ctx context.Context,
return nil, fmt.Errorf("json.Marshal(%s): %w", bpDownloadClientConfig, err)
}

req := starr.Request{URI: path.Join(bpDownloadClientConfig, fmt.Sprint(config.ID)), Body: &body}
req := starr.Request{URI: path.Join(bpDownloadClientConfig, starr.Str(config.ID)), Body: &body}
if err := l.PutInto(ctx, req, &output); err != nil {
return nil, fmt.Errorf("api.Put(%s): %w", &req, err)
}
Expand Down
Loading

0 comments on commit 9017431

Please sign in to comment.